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


see 
https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples
see http://rubydoc.info/github/rspec/rspec-core/master/RSpec/Core/SharedContext

HTH,
David
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to