Skip to content
This repository
  • 16 commits
  • 25 files changed
  • 0 comments
  • 3 contributors
11  Gemfile
... ...
@@ -1,13 +1,14 @@
1 1
 source "http://rubygems.org"
2 2
 
  3
+%w[rspec-core rspec-expectations rspec-mocks].each do |lib|
  4
+  gem lib, :path => File.expand_path("../../#{lib}", __FILE__)
  5
+end
  6
+
3 7
 gem "rake"
4  
-gem "cucumber"
5  
-gem "aruba", ">= 0.2.0"
  8
+gem "cucumber", "0.8.5"
  9
+gem "aruba", "0.2.2"
6 10
 gem "autotest"
7 11
 gem "diff-lcs"
8  
-gem "rspec-expectations", :path => "."
9  
-gem "rspec-core", :path => "../rspec-core"
10  
-gem "rspec-mocks", :path => "../rspec-mocks"
11 12
 gem "watchr"
12 13
 gem "rcov"
13 14
 gem "relish"
7  History.markdown
Source Rendered
... ...
@@ -1,5 +1,12 @@
1 1
 ## rspec-expectations release history (incomplete)
2 2
 
  3
+### 2.0.1 / 2010-10-18
  4
+
  5
+[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0...v2.0.1)
  6
+
  7
+* Enhancements
  8
+  * Make dependencies on other rspec gems consistent across gems
  9
+
3 10
 ### 2.0.0 / 2010-10-10
4 11
 
5 12
 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.rc...v2.0.0)
10  README.markdown
Source Rendered
@@ -3,6 +3,16 @@
3 3
 rspec-expectations adds `should` and `should_not` to every object and includes
4 4
 RSpec::Matchers, a library of standard matchers.
5 5
 
  6
+## Documentation
  7
+
  8
+* [Cucumber features](http://relishapp.com/rspec/rspec-expectations/v/2-0)
  9
+* [RDoc](http://rubydoc.info/gems/rspec-expectations/2.0.1/frames)
  10
+
  11
+## Install
  12
+
  13
+    gem install rspec               # for rspec-core, rspec-expectations, rspec-mocks
  14
+    gem install rspec-expecctations # for rspec-core only
  15
+
6 16
 ## Matchers
7 17
 
8 18
 Matchers are objects used to compose expectations:
2  Rakefile
@@ -58,7 +58,7 @@ end
58 58
 desc "Push cukes to relishapp using the relish-client-gem"
59 59
 task :relish, :version do |t, args|
60 60
   raise "rake relish[VERSION]" unless args[:version]
61  
-  sh "bundle exec relish --organization rspec --project rspec-expectations -v #{args[:version]} push"
  61
+  sh "bundle exec relish push --organization rspec --project rspec-expectations -v #{args[:version]}"
62 62
 end
63 63
 
64 64
 task :clobber do
44  features/matchers/exist.feature
... ...
@@ -0,0 +1,44 @@
  1
+Feature: exist matcher
  2
+
  3
+  The exist matcher is used to specify that something exists
  4
+  (as indicated by #exist?):
  5
+
  6
+    obj.should exist # passes if obj.exist?
  7
+
  8
+  Scenario: basic usage
  9
+    Given a file named "exist_matcher_spec.rb" with:
  10
+      """
  11
+      class Planet
  12
+        attr_reader :name
  13
+
  14
+        def initialize(name)
  15
+          @name = name
  16
+        end
  17
+
  18
+        def inspect
  19
+          "<Planet: #{name}>"
  20
+        end
  21
+
  22
+        def exist?
  23
+          %w[Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune].include?(name)
  24
+        end
  25
+      end
  26
+
  27
+      describe "Earth" do
  28
+        subject { Planet.new("Earth") }
  29
+        it { should exist }
  30
+        it { should_not exist } # deliberate failure
  31
+      end
  32
+
  33
+      describe "Tatooine" do
  34
+        subject { Planet.new("Tatooine") }
  35
+        it { should_not exist }
  36
+        it { should exist } # deliberate failure
  37
+      end
  38
+      """
  39
+    When I run "rspec exist_matcher_spec.rb"
  40
+    Then the output should contain all of these:
  41
+      | 4 examples, 2 failures                |
  42
+      | expected <Planet: Earth> not to exist |
  43
+      | expected <Planet: Tatooine> to exist  |
  44
+
31  features/matchers/satisfy.feature
... ...
@@ -0,0 +1,31 @@
  1
+Feature: Satisfy matcher
  2
+
  3
+  The satisfy matcher is extremely flexible and can handle almost anything
  4
+  you want to specify.  It passes if the block you provide returns true:
  5
+
  6
+    10.should satisfy { |v| v % 5 == 0 }
  7
+    7.should_not satisfy { |v| v % 5 == 0 }
  8
+
  9
+  This flexibility comes at a cost, however: the failure message
  10
+  ("expected [actual] to satisfy block") is not very descriptive
  11
+  or helpful.  You will usually be better served by using one of
  12
+  the other built-in matchers, or writing a custom matcher.
  13
+
  14
+  Scenario: basic usage
  15
+    Given a file named "satisfy_matcher_spec.rb" with:
  16
+      """
  17
+      describe 10 do
  18
+        it { should satisfy { |v| v > 5 } }
  19
+        it { should_not satisfy { |v| v > 15 } }
  20
+
  21
+        # deliberate failures
  22
+        it { should_not satisfy { |v| v > 5 } }
  23
+        it { should satisfy { |v| v > 15 } }
  24
+      end
  25
+      """
  26
+    When I run "rspec satisfy_matcher_spec.rb"
  27
+    Then the output should contain all of these:
  28
+      | 4 examples, 2 failures           |
  29
+      | expected 10 not to satisfy block |
  30
+      | expected 10 to satisfy block     |
  31
+
85  features/matchers/throw_symbol.feature
... ...
@@ -0,0 +1,85 @@
  1
+Feature: Throw symbol matcher
  2
+
  3
+  The throw_symbol matcher is used to specify that a block of code
  4
+  throws a symbol.  The most basic form passes if any symbol is thrown:
  5
+
  6
+    expect { throw :foo }.to throw_symbol
  7
+
  8
+  You'll often want to specify that a particular symbol is thrown:
  9
+
  10
+    expect { throw :foo }.to throw_symbol(:foo)
  11
+
  12
+  If you care about the additional argument given to throw, you can
  13
+  specify that as well:
  14
+
  15
+    expect { throw :foo, 7 }.to throw_symbol(:foo, 7)
  16
+
  17
+  Scenario: basic usage
  18
+    Given a file named "throw_symbol_matcher_spec.rb" with:
  19
+      """
  20
+      describe "throw" do
  21
+        specify { expect { throw :foo    }.to     throw_symbol }
  22
+        specify { expect { throw :bar, 7 }.to     throw_symbol }
  23
+        specify { expect { 5 + 5         }.to_not throw_symbol }
  24
+
  25
+        # deliberate failures
  26
+        specify { expect { throw :foo    }.to_not throw_symbol }
  27
+        specify { expect { throw :bar, 7 }.to_not throw_symbol }
  28
+        specify { expect { 5 + 5         }.to     throw_symbol }
  29
+      end
  30
+      """
  31
+    When I run "rspec throw_symbol_matcher_spec.rb"
  32
+    Then the output should contain all of these:
  33
+      | 6 examples, 3 failures                      |
  34
+      | expected no Symbol to be thrown, got :foo   |
  35
+      | expected no Symbol to be thrown, got :bar   |
  36
+      | expected a Symbol to be thrown, got nothing |
  37
+
  38
+  Scenario: specify thrown symbol
  39
+    Given a file named "throw_symbol_matcher_spec.rb" with:
  40
+      """
  41
+      describe "throw symbol" do
  42
+        specify { expect { throw :foo    }.to     throw_symbol(:foo) }
  43
+        specify { expect { throw :foo, 7 }.to     throw_symbol(:foo) }
  44
+        specify { expect { 5 + 5         }.to_not throw_symbol(:foo) }
  45
+        specify { expect { throw :bar    }.to_not throw_symbol(:foo) }
  46
+
  47
+        # deliberate failures
  48
+        specify { expect { throw :foo    }.to_not throw_symbol(:foo) }
  49
+        specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo) }
  50
+        specify { expect { 5 + 5         }.to     throw_symbol(:foo) }
  51
+        specify { expect { throw :bar    }.to     throw_symbol(:foo) }
  52
+      end
  53
+      """
  54
+    When I run "rspec throw_symbol_matcher_spec.rb"
  55
+    Then the output should contain all of these:
  56
+      | 8 examples, 4 failures                          |
  57
+      | expected :foo not to be thrown, got :foo        |
  58
+      | expected :foo not to be thrown, got :foo with 7 |
  59
+      | expected :foo to be thrown, got nothing         |
  60
+      | expected :foo to be thrown, got :bar            |
  61
+
  62
+  Scenario: specify thrown symbol and argument
  63
+    Given a file named "throw_symbol_argument_matcher_spec.rb" with:
  64
+      """
  65
+      describe "throw symbol with argument" do
  66
+        specify { expect { throw :foo, 7 }.to     throw_symbol(:foo, 7) }
  67
+        specify { expect { throw :foo, 8 }.to_not throw_symbol(:foo, 7) }
  68
+        specify { expect { throw :bar, 7 }.to_not throw_symbol(:foo, 7) }
  69
+        specify { expect { throw :foo    }.to_not throw_symbol(:foo, 7) }
  70
+
  71
+        # deliberate failures
  72
+        specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo, 7) }
  73
+        specify { expect { throw :foo, 8 }.to     throw_symbol(:foo, 7) }
  74
+        specify { expect { throw :bar, 7 }.to     throw_symbol(:foo, 7) }
  75
+        specify { expect { throw :foo    }.to     throw_symbol(:foo, 7) }
  76
+      end
  77
+      """
  78
+    When I run "rspec throw_symbol_argument_matcher_spec.rb"
  79
+    Then the output should contain all of these:
  80
+      | 8 examples, 4 failures                                       |
  81
+      | expected :foo with 7 not to be thrown, got :foo with 7       |
  82
+      | expected :foo with 7 to be thrown, got :foo with 8           |
  83
+      | expected :foo with 7 to be thrown, got :bar                  |
  84
+      | expected :foo with 7 to be thrown, got :foo with no argument |
  85
+
114  features/matchers/types.feature
... ...
@@ -0,0 +1,114 @@
  1
+Feature: Type Check matchers
  2
+
  3
+  rspec-expectations includes two matchers specify types of objects:
  4
+
  5
+    * obj.should be_kind_of(type): calls obj.kind_of?(type), which returns
  6
+      true if type is in obj's class hierarchy or is a module and is
  7
+      included in a class in obj's class hierarchy.
  8
+    * obj.should be_instance_of(type): calls obj.instance_of?(type), which
  9
+      returns true if and only if type if obj's class.
  10
+
  11
+  Both of these matchers have aliases:
  12
+
  13
+    * obj.should be_a_kind_of(type) # same as obj.should be_kind_of(type)
  14
+    * obj.should be_a(type) # same as obj.should be_kind_of(type)
  15
+    * obj.should be_an(type) # same as obj.should be_kind_of(type)
  16
+    * obj.should be_an_instance_of(type) # same as obj.should be_instance_of(type)
  17
+
  18
+  Scenario: be_(a_)kind_of matcher
  19
+    Given a file named "be_kind_of_matcher_spec.rb" with:
  20
+      """
  21
+      module MyModule; end
  22
+
  23
+      class Fixnum
  24
+        include MyModule
  25
+      end
  26
+
  27
+      describe 17 do
  28
+        # the actual class
  29
+        it { should be_kind_of(Fixnum) }
  30
+        it { should be_a_kind_of(Fixnum) }
  31
+        it { should be_a(Fixnum) }
  32
+
  33
+        # the superclass
  34
+        it { should be_kind_of(Integer) }
  35
+        it { should be_a_kind_of(Integer) }
  36
+        it { should be_an(Integer) }
  37
+
  38
+        # an included module
  39
+        it { should be_kind_of(MyModule) }
  40
+        it { should be_a_kind_of(MyModule) }
  41
+        it { should be_a(MyModule) }
  42
+
  43
+        # negative passing case
  44
+        it { should_not be_kind_of(String) }
  45
+        it { should_not be_a_kind_of(String) }
  46
+        it { should_not be_a(String) }
  47
+
  48
+        # deliberate failures
  49
+        it { should_not be_kind_of(Fixnum) }
  50
+        it { should_not be_a_kind_of(Fixnum) }
  51
+        it { should_not be_a(Fixnum) }
  52
+        it { should_not be_kind_of(Integer) }
  53
+        it { should_not be_a_kind_of(Integer) }
  54
+        it { should_not be_an(Integer) }
  55
+        it { should_not be_kind_of(MyModule) }
  56
+        it { should_not be_a_kind_of(MyModule) }
  57
+        it { should_not be_a(MyModule) }
  58
+        it { should be_kind_of(String) }
  59
+        it { should be_a_kind_of(String) }
  60
+        it { should be_a(String) }
  61
+      end
  62
+      """
  63
+    When I run "rspec be_kind_of_matcher_spec.rb"
  64
+    Then the output should contain all of these:
  65
+      | 24 examples, 12 failures                 |
  66
+      | expected 17 not to be a kind of Fixnum   |
  67
+      | expected 17 not to be a kind of Integer  |
  68
+      | expected 17 not to be a kind of MyModule |
  69
+      | expected 17 to be a kind of String       |
  70
+
  71
+  Scenario: be_(an_)instance_of matcher
  72
+    Given a file named "be_instance_of_matcher_spec.rb" with:
  73
+      """
  74
+      module MyModule; end
  75
+
  76
+      class Fixnum
  77
+        include MyModule
  78
+      end
  79
+
  80
+      describe 17 do
  81
+        # the actual class
  82
+        it { should be_instance_of(Fixnum) }
  83
+        it { should be_an_instance_of(Fixnum) }
  84
+
  85
+        # the superclass
  86
+        it { should_not be_instance_of(Integer) }
  87
+        it { should_not be_an_instance_of(Integer) }
  88
+
  89
+        # an included module
  90
+        it { should_not be_instance_of(MyModule) }
  91
+        it { should_not be_an_instance_of(MyModule) }
  92
+
  93
+        # another class with no relation to the subject's hierarchy
  94
+        it { should_not be_instance_of(String) }
  95
+        it { should_not be_an_instance_of(String) }
  96
+
  97
+        # deliberate failures
  98
+        it { should_not be_instance_of(Fixnum) }
  99
+        it { should_not be_an_instance_of(Fixnum) }
  100
+        it { should be_instance_of(Integer) }
  101
+        it { should be_an_instance_of(Integer) }
  102
+        it { should be_instance_of(MyModule) }
  103
+        it { should be_an_instance_of(MyModule) }
  104
+        it { should be_instance_of(String) }
  105
+        it { should be_an_instance_of(String) }
  106
+      end
  107
+      """
  108
+    When I run "rspec be_instance_of_matcher_spec.rb"
  109
+    Then the output should contain all of these:
  110
+      | 16 examples, 8 failures                     |
  111
+      | expected 17 not to be an instance of Fixnum |
  112
+      | expected 17 to be an instance of Integer    |
  113
+      | expected 17 to be an instance of MyModule   |
  114
+      | expected 17 to be an instance of String     |
6  features/test_frameworks/test_unit.feature
@@ -31,12 +31,16 @@ Feature: Test::Unit integration
31 31
           array.should be_empty
32 32
         end
33 33
 
  34
+        def test_expect_matcher
  35
+          expect { @a = 5 }.to change { @a }.from(nil).to(5)
  36
+        end
  37
+
34 38
         def test_custom_matcher_and_deprecation_warning
35 39
           1.should be_an_int
36 40
         end
37 41
       end
38 42
       """
39 43
      When I run "ruby rspec_expectations_test.rb"
40  
-     Then the output should contain "3 tests, 0 assertions, 1 failures, 0 errors" or "3 tests, 0 assertions, 0 failures, 1 errors"
  44
+     Then the output should contain "4 tests, 0 assertions, 1 failures, 0 errors" or "4 tests, 0 assertions, 0 failures, 1 errors"
41 45
       And the output should contain "expected empty? to return true, got false"
42 46
       And the output should contain "be_an_int is deprecated"
2  lib/rspec/expectations.rb
... ...
@@ -1,8 +1,8 @@
  1
+require 'rspec/expectations/extensions'
1 2
 require 'rspec/matchers'
2 3
 require 'rspec/expectations/fail_with'
3 4
 require 'rspec/expectations/errors'
4 5
 require 'rspec/expectations/deprecation'
5  
-require 'rspec/expectations/extensions'
6 6
 require 'rspec/expectations/handler'
7 7
 require 'rspec/expectations/version'
8 8
 require 'rspec/expectations/backward_compatibility'
1  lib/rspec/expectations/extensions.rb
... ...
@@ -1,3 +1,2 @@
1 1
 require 'rspec/expectations/extensions/kernel'
2 2
 require 'rspec/expectations/extensions/array'
3  
-require 'rspec/expectations/extensions/rspec/core/example_group'
19  lib/rspec/expectations/extensions/rspec/core/example_group.rb
... ...
@@ -1,19 +0,0 @@
1  
-module RSpec
2  
-  module Core
3  
-    class ExampleGroup
4  
-      module BlockAliases
5  
-        alias_method :to,     :should
6  
-        alias_method :to_not, :should_not
7  
-      end
8  
-
9  
-      # Extends the submitted block with aliases to and to_not
10  
-      # for should and should_not. Allows expectations like this:
11  
-      #
12  
-      #   expect { this_block }.to change{this.expression}.from(old_value).to(new_value)
13  
-      #   expect { this_block }.to raise_error
14  
-      def expect(&block)
15  
-        block.extend BlockAliases
16  
-      end
17  
-    end
18  
-  end
19  
-end
2  lib/rspec/expectations/version.rb
... ...
@@ -1,7 +1,7 @@
1 1
 module RSpec # :nodoc:
2 2
   module Expectations # :nodoc:
3 3
     module Version # :nodoc:
4  
-      STRING = '2.0.0'
  4
+      STRING = '2.0.2.pre'
5 5
     end
6 6
   end
7 7
 end
1  lib/rspec/matchers.rb
@@ -177,6 +177,7 @@ module Matchers
177 177
 require 'rspec/matchers/be_close'
178 178
 require 'rspec/matchers/be_instance_of'
179 179
 require 'rspec/matchers/be_kind_of'
  180
+require 'rspec/matchers/block_aliases'
180 181
 require 'rspec/matchers/change'
181 182
 require 'rspec/matchers/eq'
182 183
 require 'rspec/matchers/eql'
18  lib/rspec/matchers/block_aliases.rb
... ...
@@ -0,0 +1,18 @@
  1
+module RSpec
  2
+  module Matchers
  3
+    module BlockAliases
  4
+      alias_method :to,     :should
  5
+      alias_method :to_not, :should_not
  6
+    end
  7
+
  8
+    # Extends the submitted block with aliases to and to_not
  9
+    # for should and should_not. Allows expectations like this:
  10
+    #
  11
+    #   expect { this_block }.to change{this.expression}.from(old_value).to(new_value)
  12
+    #   expect { this_block }.to raise_error
  13
+    def expect(&block)
  14
+      block.extend BlockAliases
  15
+    end
  16
+  end
  17
+end
  18
+
2  lib/rspec/matchers/have.rb
@@ -75,7 +75,7 @@ def respond_to?(sym)
75 75
       
76 76
       def method_missing(sym, *args, &block)
77 77
         @collection_name = sym
78  
-        if inflector = (defined?(ActiveSupport::Inflector) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
  78
+        if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
79 79
           @plural_collection_name = inflector.pluralize(sym.to_s)
80 80
         end
81 81
         @args = args
8  lib/rspec/matchers/matcher.rb
@@ -97,11 +97,9 @@ def diffable
97 97
       
98 98
       # See RSpec::Matchers
99 99
       def chain(method, &block)
100  
-        self.class.class_eval do
101  
-          define_method method do |*args|
102  
-            block.call(*args)
103  
-            self
104  
-          end
  100
+        define_method method do |*args|
  101
+          block.call(*args)
  102
+          self
105 103
         end
106 104
       end
107 105
       
9  lib/rspec/matchers/operator_matcher.rb
@@ -29,6 +29,15 @@ def self.use_custom_matcher_or_delegate(operator)
29 29
             eval_match(@actual, operator, expected)
30 30
           end
31 31
         end
  32
+
  33
+        negative_operator = operator.sub(/^=/, '!')
  34
+        if negative_operator != operator && respond_to?(negative_operator)
  35
+          define_method(negative_operator) do |expected|
  36
+            opposite_should = ::RSpec::Matchers.last_should == :should ? :should_not : :should
  37
+            raise "RSpec does not support `#{::RSpec::Matchers.last_should} #{negative_operator} expected`.  " +
  38
+                  "Use `#{opposite_should} #{operator} expected` instead."
  39
+          end
  40
+        end
32 41
       end
33 42
 
34 43
       ['==', '===', '=~', '>', '>=', '<', '<='].each do |operator|
47  lib/rspec/matchers/throw_symbol.rb
@@ -19,7 +19,12 @@ def matches?(given_proc)
19 19
                 throw :proc_did_not_throw_anything, :nothing_thrown
20 20
               end
21 21
             end
22  
-            @caught_symbol = @expected_symbol unless @caught_arg == :nothing_thrown
  22
+
  23
+            if @caught_arg == :nothing_thrown
  24
+              @caught_arg = nil
  25
+            else
  26
+              @caught_symbol = @expected_symbol
  27
+            end
23 28
           end
24 29
 
25 30
         # Ruby 1.8 uses NameError with `symbol'
@@ -42,19 +47,11 @@ def matches?(given_proc)
42 47
       end
43 48
 
44 49
       def failure_message_for_should
45  
-        if @caught_symbol
46  
-          "expected #{expected}, got #{@caught_symbol.inspect}"
47  
-        else
48  
-          "expected #{expected} but nothing was thrown"
49  
-        end
  50
+        "expected #{expected} to be thrown, got #{caught}"
50 51
       end
51 52
       
52 53
       def failure_message_for_should_not
53  
-        if @expected_symbol
54  
-          "expected #{expected} not to be thrown"
55  
-        else
56  
-          "expected no Symbol, got :#{@caught_symbol}"
57  
-        end
  54
+        "expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, got #{caught}"
58 55
       end
59 56
       
60 57
       def description
@@ -62,15 +59,29 @@ def description
62 59
       end
63 60
       
64 61
       private
65  
-      
66  
-        def expected
67  
-          @expected_symbol.nil? ? "a Symbol" : "#{@expected_symbol.inspect}#{args}"
  62
+
  63
+        def expected(symbol_desc = 'a Symbol')
  64
+          throw_description(@expected_symbol || symbol_desc, @expected_arg)
  65
+        end
  66
+
  67
+        def caught
  68
+          throw_description(@caught_symbol || 'nothing', @caught_arg)
68 69
         end
69  
-        
70  
-        def args
71  
-          @expected_arg.nil? ? "" : " with #{@expected_arg.inspect}"
  70
+
  71
+        def throw_description(symbol, arg)
  72
+          symbol_description = symbol.is_a?(String) ? symbol : symbol.inspect
  73
+
  74
+          arg_description = if arg
  75
+            " with #{arg.inspect}"
  76
+          elsif @expected_arg && @caught_symbol == @expected_symbol
  77
+            " with no argument"
  78
+          else
  79
+            ""
  80
+          end
  81
+
  82
+          symbol_description + arg_description
72 83
         end
73  
-      
  84
+
74 85
     end
75 86
  
76 87
     # :call-seq:
4  rspec-expectations.gemspec
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25 25
   s.add_runtime_dependency     'diff-lcs',    '>= 1.1.2'
26 26
   s.add_development_dependency 'cucumber',    ">= 0.6.2"
27 27
   s.add_development_dependency 'aruba',       ">= 0.1.1"
28  
-  s.add_development_dependency 'rspec-core',  ">= #{RSpec::Expectations::Version::STRING}"
29  
-  s.add_development_dependency 'rspec-mocks', ">= #{RSpec::Expectations::Version::STRING}"
  28
+  s.add_development_dependency 'rspec-core',  "~> 2.0.2.pre"
  29
+  s.add_development_dependency 'rspec-mocks', "~> 2.0.2.pre"
30 30
 end
31 31
 
12  spec/rspec/matchers/have_spec.rb
@@ -4,7 +4,7 @@
4 4
 describe "have matcher" do
5 5
 
6 6
   before(:each) do
7  
-    if defined?(::ActiveSupport::Inflector)
  7
+    if defined?(::ActiveSupport::Inflector) && ::ActiveSupport::Inflector.respond_to?(:pluralize)
8 8
       @active_support_was_defined = true
9 9
     else
10 10
       @active_support_was_defined = false
@@ -68,6 +68,16 @@ def create_collection_owner_with(n)
68 68
     owner = create_collection_owner_with(1)
69 69
     owner.should have(1).item
70 70
   end
  71
+
  72
+  context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
  73
+
  74
+    it "does not pluralize the collection name" do
  75
+      (class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
  76
+      owner = create_collection_owner_with(1)
  77
+      expect { owner.should have(1).item }.to raise_error(NoMethodError)
  78
+    end
  79
+
  80
+  end
71 81
   
72 82
   after(:each) do
73 83
     unless @active_support_was_defined
8  spec/rspec/matchers/matcher_spec.rb
@@ -334,6 +334,14 @@ def assert_equal(a,b)
334 334
         matcher.expecting('value').matches?('other value').should be_false
335 335
       end
336 336
 
  337
+      it "prevents name collisions on chainable methods from different matchers" do
  338
+        m1 = RSpec::Matchers::Matcher.new(:m1) { chain(:foo) { raise "foo in m1" } }
  339
+        m2 = RSpec::Matchers::Matcher.new(:m2) { chain(:foo) { raise "foo in m2" } }
  340
+
  341
+        expect { m1.foo }.to raise_error("foo in m1")
  342
+        expect { m2.foo }.to raise_error("foo in m2")
  343
+      end
  344
+
337 345
       context "defined using the dsl" do
338 346
         def a_method_in_the_example
339 347
           "method defined in the example"
26  spec/rspec/matchers/operator_matcher_spec.rb
@@ -21,6 +21,32 @@
21 21
   
22 22
 end
23 23
 
  24
+describe "unsupported operators", :ruby => '1.9' do
  25
+  it "raises an appropriate error for should != expected" do
  26
+    expect {
  27
+      "apple".should != "pear"
  28
+    }.to raise_error(/does not support `should != expected`.  Use `should_not == expected`/)
  29
+  end
  30
+
  31
+  it "raises an appropriate error for should_not != expected" do
  32
+    expect {
  33
+      "apple".should_not != "pear"
  34
+    }.to raise_error(/does not support `should_not != expected`.  Use `should == expected`/)
  35
+  end
  36
+
  37
+  it "raises an appropriate error for should !~ expected" do
  38
+    expect {
  39
+      "apple".should !~ /regex/
  40
+    }.to raise_error(/does not support `should !~ expected`.  Use `should_not =~ expected`/)
  41
+  end
  42
+
  43
+  it "raises an appropriate error for should_not !~ expected" do
  44
+    expect {
  45
+      "apple".should_not !~ /regex/
  46
+    }.to raise_error(/does not support `should_not !~ expected`.  Use `should =~ expected`/)
  47
+  end
  48
+end
  49
+
24 50
 describe "should_not ==" do
25 51
   
26 52
   it "delegates message to target" do
24  spec/rspec/matchers/throw_symbol_spec.rb
@@ -17,11 +17,11 @@ module Matchers
17 17
         end
18 18
         it "provides a failure message" do
19 19
           @matcher.matches?(lambda{})
20  
-          @matcher.failure_message_for_should.should == "expected a Symbol but nothing was thrown"
  20
+          @matcher.failure_message_for_should.should == "expected a Symbol to be thrown, got nothing"
21 21
         end
22 22
         it "provides a negative failure message" do
23 23
           @matcher.matches?(lambda{ throw :sym})
24  
-          @matcher.failure_message_for_should_not.should == "expected no Symbol, got :sym"
  24
+          @matcher.failure_message_for_should_not.should == "expected no Symbol to be thrown, got :sym"
25 25
         end
26 26
       end
27 27
           
@@ -42,15 +42,15 @@ module Matchers
42 42
         end
43 43
         it "provides a failure message when no Symbol is thrown" do
44 44
           @matcher.matches?(lambda{})
45  
-          @matcher.failure_message_for_should.should == "expected :sym but nothing was thrown"
  45
+          @matcher.failure_message_for_should.should == "expected :sym to be thrown, got nothing"
46 46
         end
47 47
         it "provides a failure message when wrong Symbol is thrown" do
48 48
           @matcher.matches?(lambda{ throw :other_sym })
49  
-          @matcher.failure_message_for_should.should == "expected :sym, got :other_sym"
  49
+          @matcher.failure_message_for_should.should == "expected :sym to be thrown, got :other_sym"
50 50
         end
51 51
         it "provides a negative failure message" do
52 52
           @matcher.matches?(lambda{ throw :sym })
53  
-          @matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
  53
+          @matcher.failure_message_for_should_not.should == "expected :sym not to be thrown, got :sym"
54 54
         end
55 55
         it "only matches NameErrors raised by uncaught throws" do
56 56
           @matcher.matches?(lambda{ sym }).should be_false
@@ -77,15 +77,23 @@ module Matchers
77 77
         end
78 78
         it "provides a failure message when no Symbol is thrown" do
79 79
           @matcher.matches?(lambda{})
80  
-          @matcher.failure_message_for_should.should == %q[expected :sym with "a" but nothing was thrown]
  80
+          @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got nothing]
81 81
         end
82 82
         it "provides a failure message when wrong Symbol is thrown" do
83 83
           @matcher.matches?(lambda{ throw :other_sym })
84  
-          @matcher.failure_message_for_should.should == %q[expected :sym with "a", got :other_sym]
  84
+          @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :other_sym]
  85
+        end
  86
+        it "provides a failure message when wrong arg is thrown" do
  87
+          @matcher.matches?(lambda{ throw :sym, "b" })
  88
+          @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with "b"]
  89
+        end
  90
+        it "provides a failure message when no arg is thrown" do
  91
+          @matcher.matches?(lambda{ throw :sym })
  92
+          @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with no argument]
85 93
         end
86 94
         it "provides a negative failure message" do
87 95
           @matcher.matches?(lambda{ throw :sym })
88  
-          @matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
  96
+          @matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown, got :sym with no argument]
89 97
         end
90 98
         it "only matches NameErrors raised by uncaught throws" do
91 99
           @matcher.matches?(lambda{ sym }).should be_false
12  spec/spec_helper.rb
@@ -49,5 +49,17 @@ def fail_with(message)
49 49
   config.include RSpec::Mocks::Methods
50 50
   config.color_enabled = true
51 51
   config.filter_run :focused => true
  52
+
  53
+  config.filter_run_excluding :ruby => lambda {|version|
  54
+    case version.to_s
  55
+    when "!jruby"
  56
+      RUBY_ENGINE != "jruby"
  57
+    when /^> (.*)/
  58
+      !(RUBY_VERSION.to_s > $1)
  59
+    else
  60
+      !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
  61
+    end
  62
+  }
  63
+
52 64
   config.run_all_when_everything_filtered = true
53 65
 end

No commit comments for this range

Something went wrong with that request. Please try again.