Skip to content

Instantly share code, notes, and snippets.

@markburns
Created November 20, 2012 06:29
Show Gist options
  • Select an option

  • Save markburns/4116391 to your computer and use it in GitHub Desktop.

Select an option

Save markburns/4116391 to your computer and use it in GitHub Desktop.
Problem with include_context and shared_examples_for
source :rubygems
gem 'rspec'
.F
Failures:
1) Egg
Failure/Error: Egg.new.class.should == RSpec::Mocks::Mock
expected: RSpec::Mocks::Mock
got: Egg (using ==)
Diff:
@@ -1,2 +1,2 @@
-RSpec::Mocks::Mock
+Egg
# ./spec/shared_example_bug_spec.rb:30:in `block (2 levels) in <top (required)>'
Finished in 0.00236 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec/shared_example_bug_spec.rb:29 # Egg
require File.expand_path('spec/spec_helper')
class Egg
end
shared_context "egg mocking" do
before do
Egg.stub(:new).and_return mock('egg')
end
end
describe Egg do
include_context 'egg mocking'
specify do
Egg.new.class.should == RSpec::Mocks::Mock
end
end
shared_examples_for 'an egg mocker' do
include_context 'egg mocking'
end
describe Egg do
it_behaves_like 'an egg mocker'
specify do
Egg.new.class.should == RSpec::Mocks::Mock
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment