Thank you.

Here is what I did to conform my gem spec to the conventions suggested
at 
https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples...

my spec/spec_helper.rb...

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
# Dir["spec/support/**/*.rb"].each {|f| require f} # this did not
work...

require 'rubygems'
require 'rum_92265'
require 'rspec'
require 'rspec/autorun'
require 'support/shared_examples' # this did

now, at the top of in lib/rum_92265.rb...

require "rum_92265/version"
require File.dirname(__FILE__) + "/../spec/support/shared_examples.rb"

finally, here are the top lines of the spec/support/
shared_sample.rb...

extend RSpec::Core::SharedContext

shared_examples_for "Rum92265::A3::PartB" do

...

Anyway, I hadn't seen any gems with shared example groups exposed, so
this was the best I could come up with -- it worked. It seems weird to
require shared_samples.rb from the lib directory, but I couldn't see
where else -- gemspec, for example? -- to require it.

Lille

On Dec 12, 9:06 am, David Chelimsky <dchelim...@gmail.com> wrote:
> On Dec 11, 2011, at 4:02 PM, Lille wrote:
>
> > Hi,
>
> > I have shared examples in a gem...
>
> > some_gem_name/spec/some_gem_name/shared_examples.rb
>
> > ...where the shared examples are contained in a module, e.g.,
>
> > module SharedExamples
>
> >   shared_examples_for ...
>
> > end
>
> How does this even work? shared_examples_for is not defined in Module, so 
> unless you're leaving something important out, that should raise an error.
>
> > How can I include these shared examples in tests in a different gem
> > that depends on my some_gem_name, above? Maybe I can refer to the
> > shared examples in my dependent gem's spec_helper?
>
> There are two ways you can do this:
>
> shared_examples "stuff" do
>   before { ... }
>   let(:name) { value }
>   it "does something" do
>     # ..
>   end
> end
>
> As long as this file is required somewhere (only once, please) you can use 
> those examples in your gem or any other gem:
>
> describe Something do
>   it_behaves_like "stuff"
> end
>
> You can also define a module:
>
> module SharedExamples
>   extend RSpec::Core::SharedContext
>   before { ... }
>   let(:name) { value }
>   it "does something" do
>     # ..
>   end
> end
>
> Now you can do a standard Ruby include
>
> describe Something do
>   include SharedExamples
> end
>
> seehttps://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared...
> seehttp://rubydoc.info/github/rspec/rspec-core/master/RSpec/Core/SharedC...
>
> HTH,
> David
> _______________________________________________
> rspec-users mailing list
> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to