Skip to content

Commit

Permalink
Give a useful error when let or subject called without a block.
Browse files Browse the repository at this point in the history
This is done by nil chcking the block in let before using it.

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information
Sam Phippen committed Apr 5, 2013
1 parent bbfa594 commit dc81660
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rspec/core/memoized_helpers.rb
Expand Up @@ -191,6 +191,7 @@ module ClassMethods
def let(name, &block)
# We have to pass the block directly to `define_method` to
# allow it to use method constructs like `super` and `return`.
raise "#let or #subject called without a block" if block.nil?
MemoizedHelpers.module_for(self).define_method(name, &block)

# Apply the memoization. The method has been defined in an ancestor
Expand Down
4 changes: 3 additions & 1 deletion spec/rspec/core/memoized_helpers_spec.rb
Expand Up @@ -524,7 +524,9 @@ def count
end

it 'raises a useful error when called without a block' do
ExampleGroup.describe { let(:list) }
expect do
ExampleGroup.describe { let(:list) }
end.to raise_error(/#let or #subject called without a block/)
end

let(:a_value) { "a string" }
Expand Down

0 comments on commit dc81660

Please sign in to comment.