Skip to content
Browse files

Add scenarios for have_xxx (mapped to has_xxx?) predicate matchers.

  • Loading branch information...
1 parent a0fb168 commit d8e2772ac523b48726202909c7ed04b8b223163d @myronmarston myronmarston committed Oct 2, 2010
Showing with 49 additions and 0 deletions.
  1. +49 −0 features/matchers/predicates.feature
View
49 features/matchers/predicates.feature
@@ -39,3 +39,52 @@ Feature: predicate matchers
When I run "rspec ./should_not_be_empty_spec.rb"
Then the output should contain "2 examples, 1 failure"
And the output should contain "expected empty? to return false, got true"
+
+ Scenario: should have_key (based on Hash#has_key?)
+ Given a file named "should_have_key_spec.rb" with:
+ """
+ describe Hash do
+ context 'with :foo => 7' do
+ it 'reports that it has the key :foo' do
+ { :foo => 7 }.should have_key(:foo)
+ end
+ end
+
+ context 'with nothing' do
+ it "has no keys, but we'll fail this spec anyway" do
+ {}.should have_key(:foo)
+ end
+ end
+ end
+ """
+ When I run "rspec ./should_have_key_spec.rb"
+ Then the output should contain "2 examples, 1 failure"
+ And the output should contain "expected #has_key?(:foo) to return true, got false"
+
+ Scenario: should_not have_all_string_keys (based on custom #has_all_string_keys? method)
+ Given a file named "should_not_have_all_string_keys_spec.rb" with:
+ """
+ class Hash
+ def has_all_string_keys?
+ keys.all? { |k| String === k }
+ end
+ end
+
+ describe Hash do
+ context 'with symbol keys' do
+ it "does not have all string keys" do
+ { :foo => 7, :bar => 5 }.should_not have_all_string_keys
+ end
+ end
+
+ context 'with string keys' do
+ it "has all string keys, and we'll fail this spec anyway" do
+ { 'foo' => 7, 'bar' => 5 }.should_not have_all_string_keys
+ end
+ end
+ end
+ """
+ When I run "rspec ./should_not_have_all_string_keys_spec.rb"
+ Then the output should contain "2 examples, 1 failure"
+ And the output should contain "expected #has_all_string_keys?(nil) to return false, got true"
+

0 comments on commit d8e2772

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