lib/rspec/its.rb in rspec-its-1.2.0 vs lib/rspec/its.rb in rspec-its-1.3.0

- old
+ new

@@ -53,29 +53,48 @@ # # its([:max_users]) { should eq(3) } # its(['admin']) { should eq(:all_permissions) } # its(['john_doe', :permissions]) { should eq([:read, :write]) } # - # # You can still access to its regular methods this way: + # # You can still access its regular methods this way: # its(:keys) { should include(:max_users) } # its(:count) { should eq(2) } # end # # With an implicit subject, `is_expected` can be used as an alternative - # to `should` (e.g. for one-liner use) + # to `should` (e.g. for one-liner use). An `are_expected` alias is also + # supplied. # # @example # # describe Array do # 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 + # With an implicit subject, `will` can be used as an alternative + # to `expect { subject.attribute }.to matcher` (e.g. for one-liner use). # # @example # + # describe Array do + # its(:foo) { will raise_error(NoMethodError) } + # end + # + # With an implicit subject, `will_not` can be used as an alternative + # to `expect { subject.attribute }.to_not matcher` (e.g. for one-liner use). + # + # @example + # + # describe Array do + # its(:size) { will_not raise_error } + # end + # + # You can pass more than one argument on the `its` block to add + # some metadata to the generated example + # + # @example + # # # This ... # describe Array do # its(:size, :focus) { should eq(0) } # end # @@ -119,9 +138,23 @@ def is_expected expect(__its_subject) end alias_method :are_expected, :is_expected + + def will(matcher=nil, message=nil) + unless matcher.supports_block_expectations? + raise ArgumentError, "`will` only supports block expectations" + end + expect { __its_subject }.to matcher, message + end + + def will_not(matcher=nil, message=nil) + unless matcher.supports_block_expectations? + raise ArgumentError, "`will_not` only supports block expectations" + end + expect { __its_subject }.to_not matcher, message + end def should(matcher=nil, message=nil) RSpec::Expectations::PositiveExpectationHandler.handle_matcher(__its_subject, matcher, message) end