Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Delegated #should and #should_not for an example to the example's sub…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
jferris committed Nov 8, 2008
1 parent dc9edc6 commit dc51a97
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/spec/example/example_methods.rb
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions spec/spec/example/example_methods_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit dc51a97

Please sign in to comment.