diff --git a/lib/spec/example/example_methods.rb b/lib/spec/example/example_methods.rb index 349713220..46da108f4 100644 --- a/lib/spec/example/example_methods.rb +++ b/lib/spec/example/example_methods.rb @@ -89,6 +89,14 @@ def subject @subject ||= instance_variable_get(subject_variable_name) end + def should(matcher) + subject.should(matcher) + end + + def should_not(matcher) + subject.should_not(matcher) + end + protected include Matchers include Pending diff --git a/spec/spec/example/example_methods_spec.rb b/spec/spec/example/example_methods_spec.rb index 56725665c..bb038299e 100644 --- a/spec/spec/example/example_methods_spec.rb +++ b/spec/spec/example/example_methods_spec.rb @@ -168,6 +168,68 @@ def extract_error(&blk) example.subject.should equal(expected) end end + + describe "#should" do + with_sandboxed_options do + + attr_reader :example_group, :example, :success + + before do + @example_group = Class.new(ExampleGroup) do + def subject; @actual; end + before(:each) { @actual = 'expected' } + it { should eql('expected') } + end + @example = @example_group.examples.first + + @success = example_group.run + end + + it "should create an example using the description from the matcher" do + example.description.should == 'should eql "expected"' + end + + it "should test the matcher returned from the block" do + success.should be_true + end + + after do + ExampleGroup.reset + end + + end + end + + describe "#should_not" do + with_sandboxed_options do + + attr_reader :example_group, :example, :success + + before do + @example_group = Class.new(ExampleGroup) do + def subject; @actual; end + before(:each) { @actual = 'expected' } + it { should_not eql('unexpected') } + end + @example = @example_group.examples.first + + @success = example_group.run + end + + it "should create an example using the description from the matcher" do + example.description.should == 'should not eql "unexpected"' + end + + it "should test the matcher returned from the block" do + success.should be_true + end + + after do + ExampleGroup.reset + end + + end + end end describe "#options" do