Skip to content

Commit

Permalink
add better error message when shared context is missing
Browse files Browse the repository at this point in the history
- Closes #432.
  • Loading branch information
slawosz authored and dchelimsky committed Aug 5, 2011
1 parent 1dae214 commit 9e94666
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/rspec/core/example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

4 comments on commit 9e94666

@justinko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dchelimsky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@slawosz
Copy link
Contributor Author

@slawosz slawosz commented on 9e94666 Aug 5, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinko, @dchelimsky i will deal with it.

@dchelimsky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.