Module: RSpecCandy::Helpers::ItShouldActLike
- Defined in:
- lib/rspec_candy/helpers/it_should_act_like.rb
Class Method Summary collapse
Class Method Details
.included(by) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rspec_candy/helpers/it_should_act_like.rb', line 5 def self.included(by) by.class_eval do # Improves it_should_behave_like in some ways: # - It scopes the reused examples so #let und #subject does not bleed into the reusing example groups # - It allows to parametrize the reused example group by appending a hash argument. # Every key/value pair in the hash will become a #let variable for the reused example group # - You can call it with a block. It will be available to the reused example group as let(:block) def it_should_act_like(shared_example_group, environment = {}, &block) description = "as #{shared_example_group}" description << " (#{environment.inspect})" if environment.present? describe description do environment.each do |name, value| let(name) { value } end let(:block) { block } if block it_should_behave_like(shared_example_group) end end end end |