Skip to content

Commit

Permalink
Could forward metadata to the generated it block
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisMontagne committed Jun 8, 2014
1 parent e598fec commit 4b3bef3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/rspec/its.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ module Its
# its(:size) { is_expected.to eq(0) }
# end
#
# You can pass more than one arguments on the `its` block to add
# some options to the generated example
#
# @example
#
# # This ...
# describe Array do
# its(:size, :focus) { should eq(0) }
# end
#
# # ... generates the same runtime structure as this:
# describe Array do
# describe "size" do
# it "should eq(0)", :focus do
# subject.size.should eq(0)
# end
# end
# end
#
# Note that this method does not modify `subject` in any way, so if you
# refer to `subject` in `let` or `before` blocks, you're still
# referring to the outer subject.
Expand All @@ -78,7 +97,7 @@ module Its
# before { subject.age = 25 }
# its(:age) { should eq(25) }
# end
def its(attribute, &block)
def its(attribute, *options, &block)
describe(attribute.to_s) do
if Array === attribute
let(:__its_subject) { subject[*attribute] }
Expand All @@ -104,7 +123,7 @@ def should_not(matcher=nil, message=nil)
end

its_caller = caller.select {|file_line| file_line !~ %r(/lib/rspec/its) }
example(nil, :caller => its_caller, &block)
example(nil, *options, :caller => its_caller, &block)

end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/its_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def call_count
end.new
end

before(:each, :meta) do
subject.call_count
end

context "with some metadata" do
its(:call_count, :meta) { should eq(2) }
end

context "with a call counter" do
its(:call_count) { should eq(1) }
end
Expand Down

0 comments on commit 4b3bef3

Please sign in to comment.