This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug where subject (implicit and explicit) were not being exposed
[#744 state:resolved milestone:'Next Release']
- Loading branch information
1 parent
24cd8f5
commit ed27d45
Showing
5 changed files
with
154 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Feature: explicit subject | ||
|
||
You can override the implicit subject using the subject() method. | ||
|
||
Scenario: subject in top level group | ||
Given the following spec: | ||
""" | ||
describe Array, "with some elements" do | ||
subject { [1,2,3] } | ||
it "should have the prescribed elements" do | ||
subject.should == [1,2,3] | ||
end | ||
end | ||
""" | ||
When I run it with the spec command | ||
Then the stdout should match "1 example, 0 failures" | ||
|
||
Scenario: subject in a nested group | ||
Given the following spec: | ||
""" | ||
describe Array do | ||
subject { [1,2,3] } | ||
describe "with some elements" do | ||
it "should have the prescribed elements" do | ||
subject.should == [1,2,3] | ||
end | ||
end | ||
end | ||
""" | ||
When I run it with the spec command | ||
Then the stdout should match "1 example, 0 failures" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Feature: implicit subject | ||
|
||
The first argument to the outermost example group block is | ||
made available to each example as an implicit subject of | ||
that example. | ||
|
||
Scenario: subject in top level group | ||
Given the following spec: | ||
""" | ||
describe Array, "when first created" do | ||
it "should be empty" do | ||
subject.should == [] | ||
end | ||
end | ||
""" | ||
When I run it with the spec command | ||
Then the stdout should match "1 example, 0 failures" | ||
|
||
Scenario: subject in a nested group | ||
Given the following spec: | ||
""" | ||
describe Array do | ||
describe "when first created" do | ||
it "should be empty" do | ||
subject.should == [] | ||
end | ||
end | ||
end | ||
""" | ||
When I run it with the spec command | ||
Then the stdout should match "1 example, 0 failures" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper' | ||
|
||
module Spec | ||
module Example | ||
describe "implicit subject" do | ||
describe "with a class" do | ||
it "returns an instance of the class" do | ||
group = Class.new(ExampleGroupDouble).describe(Array) | ||
example = group.new(ExampleProxy.new) | ||
example.subject.should == [] | ||
end | ||
end | ||
|
||
describe "with a Module" do | ||
it "returns the Module" do | ||
group = Class.new(ExampleGroupDouble).describe(Enumerable) | ||
example = group.new(ExampleProxy.new) | ||
example.subject.should == Enumerable | ||
end | ||
end | ||
|
||
describe "with a string" do | ||
it "return the string" do | ||
group = Class.new(ExampleGroupDouble).describe('foo') | ||
example = group.new(ExampleProxy.new) | ||
example.subject.should == 'foo' | ||
end | ||
end | ||
|
||
describe "with a number" do | ||
it "returns the number" do | ||
group = Class.new(ExampleGroupDouble).describe(15) | ||
example = group.new(ExampleProxy.new) | ||
example.subject.should == 15 | ||
end | ||
end | ||
|
||
end | ||
|
||
describe "explicit subject" do | ||
describe "defined in a top level group" do | ||
it "replaces the implicit subject in that group" do | ||
group = Class.new(ExampleGroupDouble).describe(Array) | ||
group.subject { [1,2,3] } | ||
example = group.new(ExampleProxy.new) | ||
example.subject.should == [1,2,3] | ||
end | ||
end | ||
|
||
describe "defined in a top level group" do | ||
it "is available in a nested group (subclass)" do | ||
klass = Class.new do | ||
extend Spec::Example::Subject::ExampleGroupMethods | ||
include Spec::Example::Subject::ExampleMethods | ||
class << self | ||
def described_class | ||
Array | ||
end | ||
end | ||
def described_class | ||
self.class.described_class | ||
end | ||
|
||
subject { | ||
[1,2,3] | ||
} | ||
end | ||
|
||
subclass = Class.new(klass) | ||
|
||
object = subclass.new | ||
object.subject.should == [1,2,3] | ||
end | ||
end | ||
end | ||
end | ||
end |