Permalink
Browse files

add better error message when shared context is missing

- Closes #432.
  • Loading branch information...
1 parent 1dae214 commit 9e94666ffb076e1efc5c721b86c8f22b2d124858 @slawosz slawosz committed with dchelimsky Aug 4, 2011
Showing with 19 additions and 1 deletion.
  1. +6 −1 lib/rspec/core/example_group.rb
  2. +13 −0 spec/rspec/core/example_group_spec.rb
@@ -90,7 +90,12 @@ class << self
alias_it_should_behave_like_to :it_behaves_like, "behaves like"
def self.include_context(name)
- module_eval(&world.shared_example_groups[name])
+ group = world.shared_example_groups[name]
+ if group
+ module_eval(&group)
+ else
+ raise ArgumentError, "shared context \"#{name}\" not found"
+ end
end
class << self
@@ -888,6 +888,19 @@ def foo; 'foo'; end
end
group.run.should be_true
end
+
+ it "should raise proper error message when shared context is not found" do
+ expect do
+ group = ExampleGroup.describe do
+ include_context "not exist"
+
+ it "accesses foo" do
+ foo.should eq('foo')
+ end
+ end
+ end.to raise_error(ArgumentError,'shared context "not exist" not found')
+ end
+
end
describe "#include_examples" do

4 comments on commit 9e94666

Contributor

justinko replied Aug 5, 2011

I was hesitant to merge this in because we currently "get" shared example groups from two different locations, so I think there should be a method for both. Here is the other location:

https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/example_group.rb#L68-72

Owner

dchelimsky replied Aug 5, 2011

Agreed that should be covered as well. @slawosz - you want to take a crack at that?

Contributor

slawosz replied Aug 5, 2011

@justinko, @dchelimsky i will deal with it.

Owner

dchelimsky replied Aug 5, 2011

@slawosz thanks for offering to do this, but I went ahead and did it myself since I saw how I wanted it to work: 940f7fe

Please sign in to comment.