rspec-expectations 2.0.0.a1 → 2.0.0.a2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/.document +3 -3
  2. data/.gitignore +1 -0
  3. data/License.txt +2 -2
  4. data/Rakefile +17 -10
  5. data/Upgrade.markdown +38 -0
  6. data/lib/rspec/expectations.rb +1 -0
  7. data/lib/rspec/expectations/extensions.rb +1 -0
  8. data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +19 -0
  9. data/lib/rspec/expectations/version.rb +16 -0
  10. data/lib/rspec/matchers.rb +0 -2
  11. data/lib/rspec/matchers/exist.rb +2 -2
  12. data/lib/rspec/matchers/extensions/instance_exec.rb +27 -19
  13. data/lib/rspec/matchers/include.rb +17 -16
  14. data/lib/rspec/matchers/matcher.rb +71 -25
  15. data/rspec-expectations.gemspec +66 -19
  16. data/spec/rspec/matchers/be_close_spec.rb +50 -0
  17. data/spec/rspec/matchers/be_instance_of_spec.rb +36 -0
  18. data/spec/rspec/matchers/be_kind_of_spec.rb +33 -0
  19. data/spec/rspec/matchers/be_spec.rb +311 -0
  20. data/spec/rspec/matchers/change_spec.rb +349 -0
  21. data/spec/rspec/matchers/compatibility_spec.rb +28 -0
  22. data/spec/rspec/matchers/description_generation_spec.rb +160 -0
  23. data/spec/rspec/matchers/dsl_spec.rb +25 -0
  24. data/spec/rspec/matchers/eql_spec.rb +33 -0
  25. data/spec/rspec/matchers/equal_spec.rb +57 -0
  26. data/spec/rspec/matchers/exist_spec.rb +65 -0
  27. data/spec/rspec/matchers/has_spec.rb +81 -0
  28. data/spec/rspec/matchers/have_spec.rb +407 -0
  29. data/spec/rspec/matchers/include_spec.rb +88 -0
  30. data/spec/rspec/matchers/match_array_spec.rb +108 -0
  31. data/spec/rspec/matchers/match_spec.rb +57 -0
  32. data/spec/rspec/matchers/matcher_methods_spec.rb +63 -0
  33. data/spec/rspec/matchers/matcher_spec.rb +289 -0
  34. data/spec/rspec/matchers/matchers_spec.rb +2 -0
  35. data/spec/rspec/matchers/operator_matcher_spec.rb +191 -0
  36. data/spec/rspec/matchers/raise_error_spec.rb +333 -0
  37. data/spec/rspec/matchers/respond_to_spec.rb +116 -0
  38. data/spec/rspec/matchers/satisfy_spec.rb +36 -0
  39. data/spec/rspec/matchers/throw_symbol_spec.rb +96 -0
  40. data/spec/spec_helper.rb +13 -1
  41. data/spec/support/classes.rb +51 -0
  42. metadata +60 -15
  43. data/VERSION +0 -1
  44. data/VERSION.yml +0 -5
  45. data/lib/rspec/matchers/simple_matcher.rb +0 -133
  46. data/lib/rspec/matchers/wrap_expectation.rb +0 -55
  47. data/spec/rspec/expectations/wrap_expectation_spec.rb +0 -30
  48. data/spec/support/macros.rb +0 -29
@@ -0,0 +1,116 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe "should respond_to(:sym)" do
4
+
5
+ it "passes if target responds to :sym" do
6
+ Object.new.should respond_to(:methods)
7
+ end
8
+
9
+ it "fails if target does not respond to :sym" do
10
+ lambda {
11
+ "this string".should respond_to(:some_method)
12
+ }.should fail_with(%q|expected "this string" to respond to :some_method|)
13
+ end
14
+
15
+ end
16
+
17
+ describe "should respond_to(:sym).with(1).argument" do
18
+ it "passes if target responds to :sym with 1 arg" do
19
+ obj = Object.new
20
+ def obj.foo(arg); end
21
+ obj.should respond_to(:foo).with(1).argument
22
+ end
23
+
24
+ it "fails if target does not respond to :sym" do
25
+ obj = Object.new
26
+ lambda {
27
+ obj.should respond_to(:some_method).with(1).argument
28
+ }.should fail_with(/expected .* to respond to :some_method/)
29
+ end
30
+
31
+ it "fails if :sym expects 0 args" do
32
+ obj = Object.new
33
+ def obj.foo; end
34
+ lambda {
35
+ obj.should respond_to(:foo).with(1).argument
36
+ }.should fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
37
+ end
38
+
39
+ it "fails if :sym expects 2 args" do
40
+ obj = Object.new
41
+ def obj.foo(arg, arg2); end
42
+ lambda {
43
+ obj.should respond_to(:foo).with(1).argument
44
+ }.should fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
45
+ end
46
+ end
47
+
48
+ describe "should respond_to(message1, message2)" do
49
+
50
+ it "passes if target responds to both messages" do
51
+ Object.new.should respond_to('methods', 'inspect')
52
+ end
53
+
54
+ it "fails if target does not respond to first message" do
55
+ lambda {
56
+ Object.new.should respond_to('method_one', 'inspect')
57
+ }.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
58
+ end
59
+
60
+ it "fails if target does not respond to second message" do
61
+ lambda {
62
+ Object.new.should respond_to('inspect', 'method_one')
63
+ }.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
64
+ end
65
+
66
+ it "fails if target does not respond to either message" do
67
+ lambda {
68
+ Object.new.should respond_to('method_one', 'method_two')
69
+ }.should fail_with(/expected #<Object:.*> to respond to "method_one", "method_two"/)
70
+ end
71
+ end
72
+
73
+ describe "should respond_to(:sym).with(2).arguments" do
74
+ it "passes if target responds to :sym with 2 args" do
75
+ obj = Object.new
76
+ def obj.foo(a1, a2); end
77
+ obj.should respond_to(:foo).with(2).arguments
78
+ end
79
+
80
+ it "fails if target does not respond to :sym" do
81
+ obj = Object.new
82
+ lambda {
83
+ obj.should respond_to(:some_method).with(2).arguments
84
+ }.should fail_with(/expected .* to respond to :some_method/)
85
+ end
86
+
87
+ it "fails if :sym expects 0 args" do
88
+ obj = Object.new
89
+ def obj.foo; end
90
+ lambda {
91
+ obj.should respond_to(:foo).with(2).arguments
92
+ }.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
93
+ end
94
+
95
+ it "fails if :sym expects 2 args" do
96
+ obj = Object.new
97
+ def obj.foo(arg); end
98
+ lambda {
99
+ obj.should respond_to(:foo).with(2).arguments
100
+ }.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
101
+ end
102
+ end
103
+
104
+ describe "should_not respond_to(:sym)" do
105
+
106
+ it "passes if target does not respond to :sym" do
107
+ Object.new.should_not respond_to(:some_method)
108
+ end
109
+
110
+ it "fails if target responds to :sym" do
111
+ lambda {
112
+ Object.new.should_not respond_to(:methods)
113
+ }.should fail_with(/expected #<Object:.*> not to respond to :methods/)
114
+ end
115
+
116
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe "should satisfy { block }" do
4
+ it "should pass if block returns true" do
5
+ true.should satisfy { |val| val }
6
+ true.should satisfy do |val|
7
+ val
8
+ end
9
+ end
10
+
11
+ it "should fail if block returns false" do
12
+ lambda {
13
+ false.should satisfy { |val| val }
14
+ }.should fail_with("expected false to satisfy block")
15
+ lambda do
16
+ false.should satisfy do |val|
17
+ val
18
+ end
19
+ end.should fail_with("expected false to satisfy block")
20
+ end
21
+ end
22
+
23
+ describe "should_not satisfy { block }" do
24
+ it "should pass if block returns false" do
25
+ false.should_not satisfy { |val| val }
26
+ false.should_not satisfy do |val|
27
+ val
28
+ end
29
+ end
30
+
31
+ it "should fail if block returns true" do
32
+ lambda {
33
+ true.should_not satisfy { |val| val }
34
+ }.should fail_with("expected true not to satisfy block")
35
+ end
36
+ end
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Rspec
4
+ module Matchers
5
+ describe ThrowSymbol do
6
+ describe "with no args" do
7
+ before(:each) { @matcher = ThrowSymbol.new }
8
+
9
+ it "should match if any Symbol is thrown" do
10
+ @matcher.matches?(lambda{ throw :sym }).should be_true
11
+ end
12
+ it "should match if any Symbol is thrown with an arg" do
13
+ @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
14
+ end
15
+ it "should not match if no Symbol is thrown" do
16
+ @matcher.matches?(lambda{ }).should be_false
17
+ end
18
+ it "should provide a failure message" do
19
+ @matcher.matches?(lambda{})
20
+ @matcher.failure_message_for_should.should == "expected a Symbol but nothing was thrown"
21
+ end
22
+ it "should provide a negative failure message" do
23
+ @matcher.matches?(lambda{ throw :sym})
24
+ @matcher.failure_message_for_should_not.should == "expected no Symbol, got :sym"
25
+ end
26
+ end
27
+
28
+ describe "with a symbol" do
29
+ before(:each) { @matcher = ThrowSymbol.new(:sym) }
30
+
31
+ it "should match if correct Symbol is thrown" do
32
+ @matcher.matches?(lambda{ throw :sym }).should be_true
33
+ end
34
+ it "should match if correct Symbol is thrown with an arg" do
35
+ @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
36
+ end
37
+ it "should not match if no Symbol is thrown" do
38
+ @matcher.matches?(lambda{ }).should be_false
39
+ end
40
+ it "should not match if correct Symbol is thrown" do
41
+ @matcher.matches?(lambda{ throw :other_sym }).should be_false
42
+ end
43
+ it "should provide a failure message when no Symbol is thrown" do
44
+ @matcher.matches?(lambda{})
45
+ @matcher.failure_message_for_should.should == "expected :sym but nothing was thrown"
46
+ end
47
+ it "should provide a failure message when wrong Symbol is thrown" do
48
+ @matcher.matches?(lambda{ throw :other_sym })
49
+ @matcher.failure_message_for_should.should == "expected :sym, got :other_sym"
50
+ end
51
+ it "should provide a negative failure message" do
52
+ @matcher.matches?(lambda{ throw :sym })
53
+ @matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
54
+ end
55
+ it "should only match NameErrors raised by uncaught throws" do
56
+ @matcher.matches?(lambda{ sym }).should be_false
57
+ end
58
+ end
59
+
60
+ describe "with a symbol and an arg" do
61
+ before(:each) { @matcher = ThrowSymbol.new(:sym, "a") }
62
+
63
+ it "should match if correct Symbol and args are thrown" do
64
+ @matcher.matches?(lambda{ throw :sym, "a" }).should be_true
65
+ end
66
+ it "should not match if nothing is thrown" do
67
+ @matcher.matches?(lambda{ }).should be_false
68
+ end
69
+ it "should not match if other Symbol is thrown" do
70
+ @matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
71
+ end
72
+ it "should not match if no arg is thrown" do
73
+ @matcher.matches?(lambda{ throw :sym }).should be_false
74
+ end
75
+ it "should not match if wrong arg is thrown" do
76
+ @matcher.matches?(lambda{ throw :sym, "b" }).should be_false
77
+ end
78
+ it "should provide a failure message when no Symbol is thrown" do
79
+ @matcher.matches?(lambda{})
80
+ @matcher.failure_message_for_should.should == %q[expected :sym with "a" but nothing was thrown]
81
+ end
82
+ it "should provide a failure message when wrong Symbol is thrown" do
83
+ @matcher.matches?(lambda{ throw :other_sym })
84
+ @matcher.failure_message_for_should.should == %q[expected :sym with "a", got :other_sym]
85
+ end
86
+ it "should provide a negative failure message" do
87
+ @matcher.matches?(lambda{ throw :sym })
88
+ @matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
89
+ end
90
+ it "should only match NameErrors raised by uncaught throws" do
91
+ @matcher.matches?(lambda{ sym }).should be_false
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -5,6 +5,14 @@ require 'rspec/expectations'
5
5
  require 'rspec/mocks'
6
6
  require 'rspec/core'
7
7
 
8
+ Dir['./spec/support/**/*'].each do |f|
9
+ require f
10
+ end
11
+
12
+ def with_ruby(version)
13
+ yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
14
+ end
15
+
8
16
  module Rspec
9
17
  module Ruby
10
18
  class << self
@@ -17,6 +25,10 @@ end
17
25
 
18
26
  module Rspec
19
27
  module Matchers
28
+ def fail
29
+ raise_error(Rspec::Expectations::ExpectationNotMetError)
30
+ end
31
+
20
32
  def fail_with(message)
21
33
  raise_error(Rspec::Expectations::ExpectationNotMetError, message)
22
34
  end
@@ -28,4 +40,4 @@ Rspec::Core::configure do |config|
28
40
  config.include Rspec::Mocks::Methods
29
41
  config.include Rspec::Matchers
30
42
  config.color_enabled = true
31
- end
43
+ end
@@ -0,0 +1,51 @@
1
+ # This file contains various classes used by the specs.
2
+ module Rspec
3
+ module Expectations
4
+ # class ClassWithMultiWordPredicate
5
+ # def multi_word_predicate?
6
+ # true
7
+ # end
8
+ # end
9
+ #
10
+ module Helper
11
+ class CollectionWithSizeMethod
12
+ def initialize; @list = []; end
13
+ def size; @list.size; end
14
+ def push(item); @list.push(item); end
15
+ end
16
+
17
+ class CollectionWithLengthMethod
18
+ def initialize; @list = []; end
19
+ def length; @list.size; end
20
+ def push(item); @list.push(item); end
21
+ end
22
+
23
+ class CollectionOwner
24
+ attr_reader :items_in_collection_with_size_method, :items_in_collection_with_length_method
25
+
26
+ def initialize
27
+ @items_in_collection_with_size_method = CollectionWithSizeMethod.new
28
+ @items_in_collection_with_length_method = CollectionWithLengthMethod.new
29
+ end
30
+
31
+ def add_to_collection_with_size_method(item)
32
+ @items_in_collection_with_size_method.push(item)
33
+ end
34
+
35
+ def add_to_collection_with_length_method(item)
36
+ @items_in_collection_with_length_method.push(item)
37
+ end
38
+
39
+ def items_for(arg)
40
+ return [1, 2, 3] if arg == 'a'
41
+ [1]
42
+ end
43
+
44
+ def items
45
+ @items_in_collection_with_size_method
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.a1
4
+ version: 2.0.0.a2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-16 00:00:00 -04:00
13
+ date: 2010-01-24 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.0.0.a1
24
+ version: 2.0.0.a2
25
25
  version:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec-mocks
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.0.0.a1
34
+ version: 2.0.0.a2
35
35
  version:
36
36
  description:
37
37
  email: dchelimsky@gmail.com;chad.humphries@gmail.com
@@ -47,16 +47,17 @@ files:
47
47
  - License.txt
48
48
  - README.markdown
49
49
  - Rakefile
50
- - VERSION
51
- - VERSION.yml
50
+ - Upgrade.markdown
52
51
  - lib/rspec/expectations.rb
53
52
  - lib/rspec/expectations/differs/default.rb
54
53
  - lib/rspec/expectations/differs/load-diff-lcs.rb
55
54
  - lib/rspec/expectations/errors.rb
56
55
  - lib/rspec/expectations/extensions.rb
57
56
  - lib/rspec/expectations/extensions/kernel.rb
57
+ - lib/rspec/expectations/extensions/rspec/core/example_group.rb
58
58
  - lib/rspec/expectations/fail_with.rb
59
59
  - lib/rspec/expectations/handler.rb
60
+ - lib/rspec/expectations/version.rb
60
61
  - lib/rspec/matchers.rb
61
62
  - lib/rspec/matchers/be.rb
62
63
  - lib/rspec/matchers/be_close.rb
@@ -83,19 +84,40 @@ files:
83
84
  - lib/rspec/matchers/raise_error.rb
84
85
  - lib/rspec/matchers/respond_to.rb
85
86
  - lib/rspec/matchers/satisfy.rb
86
- - lib/rspec/matchers/simple_matcher.rb
87
87
  - lib/rspec/matchers/throw_symbol.rb
88
- - lib/rspec/matchers/wrap_expectation.rb
89
88
  - rspec-expectations.gemspec
90
89
  - spec/rspec/expectations/differs/default_spec.rb
91
90
  - spec/rspec/expectations/extensions/kernel_spec.rb
92
91
  - spec/rspec/expectations/fail_with_spec.rb
93
92
  - spec/rspec/expectations/handler_spec.rb
94
- - spec/rspec/expectations/wrap_expectation_spec.rb
93
+ - spec/rspec/matchers/be_close_spec.rb
94
+ - spec/rspec/matchers/be_instance_of_spec.rb
95
+ - spec/rspec/matchers/be_kind_of_spec.rb
96
+ - spec/rspec/matchers/be_spec.rb
97
+ - spec/rspec/matchers/change_spec.rb
98
+ - spec/rspec/matchers/compatibility_spec.rb
99
+ - spec/rspec/matchers/description_generation_spec.rb
100
+ - spec/rspec/matchers/dsl_spec.rb
101
+ - spec/rspec/matchers/eql_spec.rb
102
+ - spec/rspec/matchers/equal_spec.rb
103
+ - spec/rspec/matchers/exist_spec.rb
104
+ - spec/rspec/matchers/has_spec.rb
105
+ - spec/rspec/matchers/have_spec.rb
106
+ - spec/rspec/matchers/include_spec.rb
107
+ - spec/rspec/matchers/match_array_spec.rb
108
+ - spec/rspec/matchers/match_spec.rb
109
+ - spec/rspec/matchers/matcher_methods_spec.rb
110
+ - spec/rspec/matchers/matcher_spec.rb
111
+ - spec/rspec/matchers/matchers_spec.rb
112
+ - spec/rspec/matchers/operator_matcher_spec.rb
113
+ - spec/rspec/matchers/raise_error_spec.rb
114
+ - spec/rspec/matchers/respond_to_spec.rb
115
+ - spec/rspec/matchers/satisfy_spec.rb
116
+ - spec/rspec/matchers/throw_symbol_spec.rb
95
117
  - spec/spec.opts
96
118
  - spec/spec_helper.rb
97
119
  - spec/suite.rb
98
- - spec/support/macros.rb
120
+ - spec/support/classes.rb
99
121
  has_rdoc: true
100
122
  homepage: http://github.com/rspec/expectations
101
123
  licenses: []
@@ -113,13 +135,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
135
  version:
114
136
  required_rubygems_version: !ruby/object:Gem::Requirement
115
137
  requirements:
116
- - - ">="
138
+ - - ">"
117
139
  - !ruby/object:Gem::Version
118
- version: "0"
140
+ version: 1.3.1
119
141
  version:
120
142
  requirements: []
121
143
 
122
- rubyforge_project:
144
+ rubyforge_project: rspec
123
145
  rubygems_version: 1.3.5
124
146
  signing_key:
125
147
  specification_version: 3
@@ -129,7 +151,30 @@ test_files:
129
151
  - spec/rspec/expectations/extensions/kernel_spec.rb
130
152
  - spec/rspec/expectations/fail_with_spec.rb
131
153
  - spec/rspec/expectations/handler_spec.rb
132
- - spec/rspec/expectations/wrap_expectation_spec.rb
154
+ - spec/rspec/matchers/be_close_spec.rb
155
+ - spec/rspec/matchers/be_instance_of_spec.rb
156
+ - spec/rspec/matchers/be_kind_of_spec.rb
157
+ - spec/rspec/matchers/be_spec.rb
158
+ - spec/rspec/matchers/change_spec.rb
159
+ - spec/rspec/matchers/compatibility_spec.rb
160
+ - spec/rspec/matchers/description_generation_spec.rb
161
+ - spec/rspec/matchers/dsl_spec.rb
162
+ - spec/rspec/matchers/eql_spec.rb
163
+ - spec/rspec/matchers/equal_spec.rb
164
+ - spec/rspec/matchers/exist_spec.rb
165
+ - spec/rspec/matchers/has_spec.rb
166
+ - spec/rspec/matchers/have_spec.rb
167
+ - spec/rspec/matchers/include_spec.rb
168
+ - spec/rspec/matchers/match_array_spec.rb
169
+ - spec/rspec/matchers/match_spec.rb
170
+ - spec/rspec/matchers/matcher_methods_spec.rb
171
+ - spec/rspec/matchers/matcher_spec.rb
172
+ - spec/rspec/matchers/matchers_spec.rb
173
+ - spec/rspec/matchers/operator_matcher_spec.rb
174
+ - spec/rspec/matchers/raise_error_spec.rb
175
+ - spec/rspec/matchers/respond_to_spec.rb
176
+ - spec/rspec/matchers/satisfy_spec.rb
177
+ - spec/rspec/matchers/throw_symbol_spec.rb
133
178
  - spec/spec_helper.rb
134
179
  - spec/suite.rb
135
- - spec/support/macros.rb
180
+ - spec/support/classes.rb