Skip to content
Browse files

require 'ostruct' to fix bug with its([key])

- Closes #264
  • Loading branch information...
1 parent a7ff363 commit c4ee67f50b3ad3aa02ef6fb9aeb5508044275653 @Burgestrand Burgestrand committed with dchelimsky Dec 31, 2010
Showing with 35 additions and 0 deletions.
  1. +33 −0 features/subject/hash_key_of_subject.feature
  2. +2 −0 lib/rspec/core/subject.rb
View
33 features/subject/hash_key_of_subject.feature
@@ -0,0 +1,33 @@
+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"
View
2 lib/rspec/core/subject.rb
@@ -1,3 +1,5 @@
+require 'ostruct'
+
module RSpec
module Core
module Subject

0 comments on commit c4ee67f

Please sign in to comment.
Something went wrong with that request. Please try again.