Permalink
Browse files

merge two feature files

  • Loading branch information...
1 parent d794001 commit db803b303beb6293f86bfd4973858145aef74518 @dchelimsky dchelimsky committed Dec 31, 2010
Showing with 68 additions and 51 deletions.
  1. +68 −18 features/subject/attribute_of_subject.feature
  2. +0 −33 features/subject/hash_key_of_subject.feature
@@ -1,29 +1,43 @@
Feature: attribute of subject
Use the its() method as a short-hand to generate a nested example group with
- a single example that specifies the expected value of an attribute of the subject.
- This can be used with an implicit or explicit subject.
+ a single example that specifies the expected value of an attribute of the
+ subject. This can be used with an implicit or explicit subject.
- its() accepts a symbol or a string, and a block representing the example. Use
- a string with dots to specify a nested attribute (i.e. an attribute of the
- attribute of the subject).
+ its() accepts a symbol or a string, and a block representing the example.
- Scenario: simple attribute
+ its(:size) { should eq(1) }
+ its("length") { should eq(1) }
+
+ You can use a string with dots to specify a nested attribute (i.e. an
+ attribute of the attribute of the subject).
+
+ its("phone_numbers.size") { should eq(2) }
+
+ When the subject is a hash, you can pass in an array with a single key to
+ access the value at that key in the hash.
+
+ its([:key]) { should eq(value) }
+
+ Scenario: specify value of an attribute
Given a file named "example_spec.rb" with:
"""
describe Array do
- its(:size) { should == 0 }
+ context "when first created" do
+ its(:size) { should eq(0) }
+ end
end
"""
When I run "rspec example_spec.rb --format documentation"
Then the output should contain:
"""
Array
- size
- should == 0
+ when first created
+ size
+ should == 0
"""
- Scenario: nested attribute
+ Scenario: specify value of a nested attribute
Given a file named "example_spec.rb" with:
"""
class Person
@@ -34,19 +48,55 @@ Feature: attribute of subject
end
describe Person do
- subject do
- person = Person.new
- person.phone_numbers << "555-1212"
- person
- end
+ context "with one phone number (555-1212)"do
+ subject do
+ person = Person.new
+ person.phone_numbers << "555-1212"
+ person
+ end
- its("phone_numbers.first") { should == "555-1212" }
+ its("phone_numbers.first") { should eq("555-1212") }
+ end
end
"""
When I run "rspec example_spec.rb --format documentation"
Then the output should contain:
"""
Person
- phone_numbers.first
- should == "555-1212"
+ with one phone number (555-1212)
+ phone_numbers.first
+ should == 555-1212
+ """
+
+ Scenario: specify value of an attribute of a hash
+ Given a file named "example_spec.rb" with:
+ """
+ describe Hash do
+ context "with two items" do
+ subject do
+ {:one => 'one', :two => 'two'}
+ end
+
+ its(:size) { should eq(2) }
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should contain "1 example, 0 failures"
+
+ Scenario: specify value for key in a hash
+ Given a file named "example_spec.rb" with:
+ """
+ describe Hash do
+ context "with keys :one and 'two'" do
+ subject do
+ {:one => 1, "two" => 2}
+ end
+
+ its([:one]) { should eq(1) }
+ its(["two"]) { should eq(2) }
+ end
+ end
"""
+ When I run "rspec example_spec.rb"
+ Then the output should contain "2 examples, 0 failures"
@@ -1,33 +0,0 @@
-Feature: hash key of subject
-
- its() accepts an array with a single item, which will be used as a key if the
- subject is a hash. Regular attribute matchers still work the same.
-
- Scenario: simple attribute
- Given a file named "example_spec.rb" with:
- """
- describe Hash do
- subject do
- {:one => 'one', :two => 'two'}
- end
-
- its(:size) { should == 2 }
- end
- """
- When I run "rspec example_spec.rb --format documentation"
- Then the output should contain "1 example, 0 failures"
-
- Scenario: hash keys
- Given a file named "example_spec.rb" with:
- """
- describe Hash do
- subject do
- {:one => 'one', "two" => 'two'}
- end
-
- its([:one]) { should == 'one' }
- its(["two"]) { should == 'two' }
- end
- """
- When I run "rspec example_spec.rb --format documentation"
- Then the output should contain "2 examples, 0 failures"

0 comments on commit db803b3

Please sign in to comment.