rspec-expectations 2.0.0.a2 → 2.0.0.a3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README.markdown +18 -3
  2. data/Rakefile +7 -0
  3. data/Upgrade.markdown +16 -1
  4. data/lib/rspec/expectations/fail_with.rb +1 -17
  5. data/lib/rspec/expectations/version.rb +1 -1
  6. data/lib/rspec/matchers.rb +1 -0
  7. data/lib/rspec/matchers/be.rb +169 -129
  8. data/lib/rspec/matchers/eq.rb +47 -0
  9. data/lib/rspec/matchers/method_missing.rb +2 -2
  10. data/rspec-expectations.gemspec +11 -11
  11. data/spec/rspec/expectations/differs/default_spec.rb +1 -1
  12. data/spec/rspec/expectations/extensions/kernel_spec.rb +1 -1
  13. data/spec/rspec/expectations/fail_with_spec.rb +1 -8
  14. data/spec/rspec/expectations/handler_spec.rb +1 -1
  15. data/spec/rspec/matchers/be_close_spec.rb +1 -1
  16. data/spec/rspec/matchers/be_instance_of_spec.rb +1 -1
  17. data/spec/rspec/matchers/be_kind_of_spec.rb +1 -1
  18. data/spec/rspec/matchers/be_spec.rb +161 -11
  19. data/spec/rspec/matchers/change_spec.rb +1 -1
  20. data/spec/rspec/matchers/compatibility_spec.rb +1 -1
  21. data/spec/rspec/matchers/description_generation_spec.rb +1 -1
  22. data/spec/rspec/matchers/dsl_spec.rb +1 -1
  23. data/spec/rspec/matchers/eq_spec.rb +34 -0
  24. data/spec/rspec/matchers/eql_spec.rb +1 -1
  25. data/spec/rspec/matchers/equal_spec.rb +1 -1
  26. data/spec/rspec/matchers/exist_spec.rb +1 -1
  27. data/spec/rspec/matchers/has_spec.rb +1 -1
  28. data/spec/rspec/matchers/have_spec.rb +1 -1
  29. data/spec/rspec/matchers/include_spec.rb +1 -1
  30. data/spec/rspec/matchers/match_array_spec.rb +1 -1
  31. data/spec/rspec/matchers/match_spec.rb +1 -1
  32. data/spec/rspec/matchers/matchers_spec.rb +1 -1
  33. data/spec/rspec/matchers/operator_matcher_spec.rb +1 -1
  34. data/spec/rspec/matchers/raise_error_spec.rb +1 -1
  35. data/spec/rspec/matchers/respond_to_spec.rb +1 -1
  36. data/spec/rspec/matchers/satisfy_spec.rb +1 -1
  37. data/spec/rspec/matchers/throw_symbol_spec.rb +1 -1
  38. data/spec/spec_helper.rb +3 -3
  39. metadata +7 -7
  40. data/spec/rspec/matchers/matcher_methods_spec.rb +0 -63
  41. data/spec/spec.opts +0 -6
@@ -1,8 +1,23 @@
1
1
  # RSpec Expectations
2
2
 
3
- See README.markdown at [http://github.com/rspec/meta](http://github.com/rspec/meta)
3
+ rspec-expectations adds `should` and `should_not` to every object and includes
4
+ Rspec::Matchers, a library of standard matchers.
5
+
6
+ rspec-expectations is currently in alpha release. While you are welcome to
7
+ track, fork, explore, etc, we're too early in the process to start fielding
8
+ pull requests and or issues from outside the core development team, so please
9
+ don't waste your time until this notice changes.
10
+
11
+ ## Install
12
+
13
+ [sudo] gem install rspec --prerelease
14
+
15
+ This will install rspec, rspec-core, rspec-expectations and rspec-mocks.
16
+
4
17
 
5
18
  #### Also see
6
19
 
7
- * [http://github.com/rspec/core](http://github.com/rspec/core)
8
- * [http://github.com/rspec/mocks](http://github.com/rspec/mocks)
20
+ * [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
21
+ * [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core)
22
+ * [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
23
+ * [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev)
data/Rakefile CHANGED
@@ -48,3 +48,10 @@ Rake::RDocTask.new do |rdoc|
48
48
  rdoc.rdoc_files.include('lib/**/*.rb')
49
49
  end
50
50
 
51
+ task :clobber do
52
+ rm_rf 'pkg'
53
+ rm_rf 'tmp'
54
+ rm_rf 'coverage'
55
+ end
56
+
57
+
@@ -1,4 +1,19 @@
1
- # Upgrade to rspec-2.0
1
+ # Upgrade to rspec-expectations-2.0
2
+
3
+ ## What's new
4
+
5
+ ### New `eq` matcher.
6
+
7
+ `Rspec::Matchers` now offers you two approaches to differentiating between
8
+ object identity. You can use the rspec-1 approach:
9
+
10
+ actual.should == expected # object equality
11
+ actual.should equal(expected) # object identity
12
+
13
+ ... or, if you prefer:
14
+
15
+ actual.should eq(expected) # object equality
16
+ actual.should be(expected) # object identity
2
17
 
3
18
  ## What's been removed
4
19
 
@@ -13,22 +13,6 @@ module Rspec
13
13
  raise ArgumentError, "Failure message is nil. Does your matcher define the " +
14
14
  "appropriate failure_message_for_* method to return a string?"
15
15
  end
16
- if (Array === message) & (message.length == 3)
17
- ::Rspec::Core.warn(<<-NOTICE
18
-
19
- *****************************************************************
20
- DEPRECATION WARNING: you are using deprecated behaviour that will
21
- be removed from a future version of RSpec.
22
-
23
- * Support for matchers that return arrays from failure message
24
- methods is deprecated.
25
- * Instead, the matcher should return a string, and expose methods
26
- for the expected() and actual() values.
27
- *****************************************************************
28
- NOTICE
29
- )
30
- message, expected, target = message[0], message[1], message[2]
31
- end
32
16
  unless (differ.nil? || expected.nil? || target.nil?)
33
17
  if expected.is_a?(String)
34
18
  message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
@@ -40,4 +24,4 @@ NOTICE
40
24
  end
41
25
  end
42
26
  end
43
- end
27
+ end
@@ -5,7 +5,7 @@ module Rspec # :nodoc:
5
5
  MAJOR = 2
6
6
  MINOR = 0
7
7
  TINY = 0
8
- PRE = 'a2'
8
+ PRE = 'a3'
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
11
11
 
@@ -7,6 +7,7 @@ require 'rspec/matchers/be_close'
7
7
  require 'rspec/matchers/be_instance_of'
8
8
  require 'rspec/matchers/be_kind_of'
9
9
  require 'rspec/matchers/change'
10
+ require 'rspec/matchers/eq'
10
11
  require 'rspec/matchers/eql'
11
12
  require 'rspec/matchers/equal'
12
13
  require 'rspec/matchers/errors'
@@ -1,169 +1,206 @@
1
+ require 'rspec/matchers/dsl'
2
+
3
+ Rspec::Matchers.define :be_true do
4
+ match do |actual|
5
+ !!actual
6
+ end
7
+ end
8
+
9
+ Rspec::Matchers.define :be_false do
10
+ match do |actual|
11
+ !actual
12
+ end
13
+ end
14
+
15
+ Rspec::Matchers.define :be_nil do
16
+ match do |actual|
17
+ actual.nil?
18
+ end
19
+
20
+ failure_message_for_should do |actual|
21
+ "expected nil, got #{actual.inspect}"
22
+ end
23
+
24
+ failure_message_for_should_not do
25
+ "expected not nil, got nil"
26
+ end
27
+ end
28
+
1
29
  module Rspec
2
30
  module Matchers
3
-
31
+
4
32
  class Be #:nodoc:
5
33
  include Rspec::Matchers::Pretty
6
34
 
7
- def initialize(*args)
8
- @expected = args.empty? ? true : set_expected(args.shift)
35
+ def initialize(*args, &block)
9
36
  @args = args
10
- @comparison_method = nil
11
37
  end
12
38
 
13
39
  def matches?(actual)
14
40
  @actual = actual
15
- handling_predicate? ? run_predicate_on(actual) : match_or_compare(actual)
41
+ !!@actual
42
+ end
43
+
44
+ def failure_message_for_should
45
+ "expected #{@actual.inspect} to evaluate to true"
46
+ end
47
+
48
+ def failure_message_for_should_not
49
+ "expected #{@actual.inspect} to evaluate to false"
50
+ end
51
+
52
+ def description
53
+ "be"
54
+ end
55
+
56
+ [:==, :<, :<=, :>=, :>, :===].each do |operator|
57
+ define_method operator do |operand|
58
+ BeComparedTo.new(operand, operator)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def args_to_s
65
+ @args.empty? ? "" : parenthesize(inspected_args.join(', '))
66
+ end
67
+
68
+ def parenthesize(string)
69
+ return "(#{string})"
70
+ end
71
+
72
+ def inspected_args
73
+ @args.collect{|a| a.inspect}
74
+ end
75
+
76
+ def expected_to_sentence
77
+ split_words(@expected)
78
+ end
79
+
80
+ def args_to_sentence
81
+ to_sentence(@args)
82
+ end
83
+
84
+ end
85
+
86
+ class BeComparedTo < Be
87
+
88
+ def initialize(operand, operator)
89
+ @expected, @operator = operand, operator
90
+ @args = []
91
+ end
92
+
93
+ def matches?(actual)
94
+ @actual = actual
95
+ @actual.__send__(@operator, @expected)
96
+ end
97
+
98
+ def failure_message_for_should
99
+ "expected #{@operator} #{@expected}, got #{@actual.inspect}"
100
+ end
101
+
102
+ def failure_message_for_should_not
103
+ message = <<-MESSAGE
104
+ 'should_not be #{@operator} #{@expected}' not only FAILED,
105
+ it is a bit confusing.
106
+ MESSAGE
107
+
108
+ raise message << ([:===,:==].include?(@operator) ?
109
+ "It might be more clearly expressed without the \"be\"?" :
110
+ "It might be more clearly expressed in the positive?")
111
+ end
112
+
113
+ def description
114
+ "be #{@operator} #{expected_to_sentence}#{args_to_sentence}"
115
+ end
116
+
117
+ end
118
+
119
+ class BePredicate < Be
120
+
121
+ def initialize(*args, &block)
122
+ @expected = parse_expected(args.shift)
123
+ @args = args
124
+ @block = block
16
125
  end
17
126
 
18
- def run_predicate_on(actual)
127
+ def matches?(actual)
128
+ @actual = actual
19
129
  begin
20
- return @result = actual.__send__(predicate, *@args)
130
+ return @result = actual.__send__(predicate, *@args, &@block)
21
131
  rescue NameError => predicate_missing_error
22
132
  "this needs to be here or rcov will not count this branch even though it's executed in a code example"
23
133
  end
24
134
 
25
135
  begin
26
- return @result = actual.__send__(present_tense_predicate, *@args)
136
+ return @result = actual.__send__(present_tense_predicate, *@args, &@block)
27
137
  rescue NameError
28
138
  raise predicate_missing_error
29
139
  end
30
140
  end
31
141
 
32
142
  def failure_message_for_should
33
- if handling_predicate?
34
- if predicate == :nil?
35
- "expected nil, got #{@actual.inspect}"
36
- else
37
- "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
38
- end
39
- else
40
- "expected #{@comparison_method} #{expected}, got #{@actual.inspect}".gsub(' ',' ')
41
- end
143
+ "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
42
144
  end
43
145
 
44
146
  def failure_message_for_should_not
45
- if handling_predicate?
46
- if predicate == :nil?
47
- "expected not nil, got nil"
48
- else
49
- "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
50
- end
51
- else
52
- message = <<-MESSAGE
53
- 'should_not be #{@comparison_method} #{expected}' not only FAILED,
54
- it is a bit confusing.
55
- MESSAGE
56
-
57
- raise message << ([:===,:==].include?(@comparison_method) ?
58
- "It might be more clearly expressed without the \"be\"?" :
59
- "It might be more clearly expressed in the positive?")
60
- end
147
+ "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
61
148
  end
62
-
149
+
63
150
  def description
64
- "#{prefix_to_sentence}#{comparison} #{expected_to_sentence}#{args_to_sentence}".gsub(/\s+/,' ')
151
+ "#{prefix_to_sentence}#{expected_to_sentence}#{args_to_sentence}"
65
152
  end
66
153
 
67
- [:==, :<, :<=, :>=, :>, :===].each do |method|
68
- define_method method do |expected|
69
- compare_to(expected, :using => method)
70
- self
71
- end
72
- end
154
+ private
73
155
 
74
- private
75
- def match_or_compare(actual)
76
- TrueClass === @expected ? @actual : @actual.__send__(comparison_method, @expected)
77
- end
156
+ def predicate
157
+ "#{@expected}?".to_sym
158
+ end
78
159
 
79
- def comparison_method
80
- @comparison_method || :equal?
81
- end
160
+ def present_tense_predicate
161
+ "#{@expected}s?".to_sym
162
+ end
82
163
 
83
- def expected
84
- @expected
85
- end
164
+ def parse_expected(expected)
165
+ @prefix, expected = prefix_and_expected(expected)
166
+ expected
167
+ end
86
168
 
87
- def compare_to(expected, opts)
88
- @expected, @comparison_method = expected, opts[:using]
89
- end
169
+ def prefix_and_expected(symbol)
170
+ symbol.to_s =~ /^(be_(an?_)?)(.*)/
171
+ return $1, $3
172
+ end
90
173
 
91
- def set_expected(expected)
92
- Symbol === expected ? parse_expected(expected) : expected
93
- end
94
-
95
- def parse_expected(expected)
96
- ["be_an_","be_a_","be_"].each do |prefix|
97
- handling_predicate!
98
- if expected.to_s =~ /^#{prefix}/
99
- set_prefix(prefix)
100
- expected = expected.to_s.sub(prefix,"")
101
- [true, false, nil].each do |val|
102
- return val if val.to_s == expected
103
- end
104
- return expected.to_sym
105
- end
106
- end
107
- end
108
-
109
- def set_prefix(prefix)
110
- @prefix = prefix
111
- end
112
-
113
- def prefix
114
- # FIXME - this is a bit goofy - but we get failures
115
- # if just defining @prefix = nil in initialize
116
- @prefix = nil unless defined?(@prefix)
117
- @prefix
118
- end
174
+ def prefix_to_sentence
175
+ split_words(@prefix)
176
+ end
119
177
 
120
- def handling_predicate!
121
- @handling_predicate = true
122
- end
123
-
124
- def handling_predicate?
125
- return false if [true, false, nil].include?(expected)
126
- # FIXME - this is a bit goofy - but we get failures
127
- # if just defining @handling_predicate = nil or false in initialize
128
- return defined?(@handling_predicate) ? @handling_predicate : nil
129
- end
178
+ end
130
179
 
131
- def predicate
132
- "#{@expected.to_s}?".to_sym
133
- end
134
-
135
- def present_tense_predicate
136
- "#{@expected.to_s}s?".to_sym
137
- end
138
-
139
- def args_to_s
140
- @args.empty? ? "" : parenthesize(inspected_args.join(', '))
141
- end
142
-
143
- def parenthesize(string)
144
- return "(#{string})"
145
- end
146
-
147
- def inspected_args
148
- @args.collect{|a| a.inspect}
149
- end
150
-
151
- def comparison
152
- @comparison_method.nil? ? " " : "be #{@comparison_method.to_s} "
153
- end
154
-
155
- def expected_to_sentence
156
- split_words(expected)
157
- end
158
-
159
- def prefix_to_sentence
160
- split_words(prefix)
161
- end
180
+ class BeSameAs < Be
181
+
182
+ def initialize(*args, &block)
183
+ @expected = args.shift
184
+ @args = args
185
+ end
186
+
187
+ def matches?(actual)
188
+ @actual = actual
189
+ @actual.equal?(@expected)
190
+ end
191
+
192
+ def failure_message_for_should
193
+ "expected #{@expected}, got #{@actual.inspect}"
194
+ end
195
+
196
+ def failure_message_for_should_not
197
+ "expected not #{@expected}, got #{@actual.inspect}"
198
+ end
199
+
200
+ def description
201
+ "be #{expected_to_sentence}#{args_to_sentence}"
202
+ end
162
203
 
163
- def args_to_sentence
164
- to_sentence(@args)
165
- end
166
-
167
204
  end
168
205
 
169
206
  # :call-seq:
@@ -179,7 +216,7 @@ it is a bit confusing.
179
216
  # the caller should satisfy an if condition (to be or not to be).
180
217
  #
181
218
  # Predicates are any Ruby method that ends in a "?" and returns true or false.
182
- # Given be_ followed by arbitrary_predicate (without the "?"), RSpec will match
219
+ # Given be_ followed by arbitrary_predicate (without the "?"), Rspec will match
183
220
  # convert that into a query against the target object.
184
221
  #
185
222
  # The arbitrary_predicate feature will handle any predicate
@@ -197,7 +234,9 @@ it is a bit confusing.
197
234
  # target.should_not be_empty #passes unless target.empty?
198
235
  # target.should_not be_old_enough(16) #passes unless target.old_enough?(16)
199
236
  def be(*args)
200
- Matchers::Be.new(*args)
237
+ args.empty? ?
238
+ Matchers::Be.new :
239
+ Matchers::BeSameAs.new(*args)
201
240
  end
202
241
 
203
242
  # passes if target.kind_of?(klass)
@@ -208,3 +247,4 @@ it is a bit confusing.
208
247
  alias_method :be_an, :be_a
209
248
  end
210
249
  end
250
+
@@ -0,0 +1,47 @@
1
+ module Rspec
2
+ module Matchers
3
+ # :call-seq:
4
+ # should eq(expected)
5
+ # should_not eq(expected)
6
+ #
7
+ # Passes if actual == expected.
8
+ #
9
+ # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
10
+ #
11
+ # == Examples
12
+ #
13
+ # 5.should eq(5)
14
+ # 5.should_not eq(3)
15
+ def eq(expected)
16
+ Matcher.new :eq, expected do |_expected_|
17
+ match do |actual|
18
+ actual == _expected_
19
+ end
20
+
21
+ failure_message_for_should do |actual|
22
+ <<-MESSAGE
23
+
24
+ expected #{_expected_.inspect}
25
+ got #{actual.inspect}
26
+
27
+ (compared using ==)
28
+ MESSAGE
29
+ end
30
+
31
+ failure_message_for_should_not do |actual|
32
+ <<-MESSAGE
33
+
34
+ expected #{actual.inspect} not to equal #{_expected_.inspect}
35
+
36
+ (compared using ==)
37
+ MESSAGE
38
+ end
39
+
40
+ description do
41
+ "== #{_expected_}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
@@ -1,8 +1,8 @@
1
1
  module Rspec
2
2
  module Matchers
3
3
  def method_missing(sym, *args, &block) # :nodoc:
4
- return Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
5
- return Matchers::Has.new(sym, *args) if sym.to_s =~ /^have_/
4
+ return Matchers::BePredicate.new(sym, *args, &block) if sym.to_s =~ /^be_/
5
+ return Matchers::Has.new(sym, *args, &block) if sym.to_s =~ /^have_/
6
6
  super
7
7
  end
8
8
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-expectations}
8
- s.version = "2.0.0.a2"
8
+ s.version = "2.0.0.a3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Chelimsky", "Chad Humphries"]
12
- s.date = %q{2010-01-24}
12
+ s.date = %q{2010-02-03}
13
13
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
39
39
  "lib/rspec/matchers/change.rb",
40
40
  "lib/rspec/matchers/compatibility.rb",
41
41
  "lib/rspec/matchers/dsl.rb",
42
+ "lib/rspec/matchers/eq.rb",
42
43
  "lib/rspec/matchers/eql.rb",
43
44
  "lib/rspec/matchers/equal.rb",
44
45
  "lib/rspec/matchers/errors.rb",
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
71
72
  "spec/rspec/matchers/compatibility_spec.rb",
72
73
  "spec/rspec/matchers/description_generation_spec.rb",
73
74
  "spec/rspec/matchers/dsl_spec.rb",
75
+ "spec/rspec/matchers/eq_spec.rb",
74
76
  "spec/rspec/matchers/eql_spec.rb",
75
77
  "spec/rspec/matchers/equal_spec.rb",
76
78
  "spec/rspec/matchers/exist_spec.rb",
@@ -79,7 +81,6 @@ Gem::Specification.new do |s|
79
81
  "spec/rspec/matchers/include_spec.rb",
80
82
  "spec/rspec/matchers/match_array_spec.rb",
81
83
  "spec/rspec/matchers/match_spec.rb",
82
- "spec/rspec/matchers/matcher_methods_spec.rb",
83
84
  "spec/rspec/matchers/matcher_spec.rb",
84
85
  "spec/rspec/matchers/matchers_spec.rb",
85
86
  "spec/rspec/matchers/operator_matcher_spec.rb",
@@ -87,7 +88,6 @@ Gem::Specification.new do |s|
87
88
  "spec/rspec/matchers/respond_to_spec.rb",
88
89
  "spec/rspec/matchers/satisfy_spec.rb",
89
90
  "spec/rspec/matchers/throw_symbol_spec.rb",
90
- "spec/spec.opts",
91
91
  "spec/spec_helper.rb",
92
92
  "spec/suite.rb",
93
93
  "spec/support/classes.rb"
@@ -111,6 +111,7 @@ Gem::Specification.new do |s|
111
111
  "spec/rspec/matchers/compatibility_spec.rb",
112
112
  "spec/rspec/matchers/description_generation_spec.rb",
113
113
  "spec/rspec/matchers/dsl_spec.rb",
114
+ "spec/rspec/matchers/eq_spec.rb",
114
115
  "spec/rspec/matchers/eql_spec.rb",
115
116
  "spec/rspec/matchers/equal_spec.rb",
116
117
  "spec/rspec/matchers/exist_spec.rb",
@@ -119,7 +120,6 @@ Gem::Specification.new do |s|
119
120
  "spec/rspec/matchers/include_spec.rb",
120
121
  "spec/rspec/matchers/match_array_spec.rb",
121
122
  "spec/rspec/matchers/match_spec.rb",
122
- "spec/rspec/matchers/matcher_methods_spec.rb",
123
123
  "spec/rspec/matchers/matcher_spec.rb",
124
124
  "spec/rspec/matchers/matchers_spec.rb",
125
125
  "spec/rspec/matchers/operator_matcher_spec.rb",
@@ -137,15 +137,15 @@ Gem::Specification.new do |s|
137
137
  s.specification_version = 3
138
138
 
139
139
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
140
- s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.a2"])
141
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.a2"])
140
+ s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.a3"])
141
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.a3"])
142
142
  else
143
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.a2"])
144
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a2"])
143
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.a3"])
144
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a3"])
145
145
  end
146
146
  else
147
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.a2"])
148
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a2"])
147
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.a3"])
148
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a3"])
149
149
  end
150
150
  end
151
151
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
  require 'ostruct'
3
3
 
4
4
  module Rspec
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Object, "#should" do
4
4
  before(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Expectations, "#fail_with with no diff" do
4
4
  before(:each) do
@@ -21,13 +21,6 @@ describe Rspec::Expectations, "#fail_with with Array" do
21
21
  before(:each) do
22
22
  Rspec::Core.stub!(:warn)
23
23
  end
24
-
25
- it "is deprecated" do
26
- Rspec::Core.should_receive(:warn)
27
- lambda {
28
- Rspec::Expectations.fail_with ["message", "expected", "actual"]
29
- }.should raise_error
30
- end
31
24
  end
32
25
 
33
26
  describe Rspec::Expectations, "#fail_with with diff" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  module ExampleExpectations
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
  module Rspec
3
3
  module Matchers
4
4
  describe "[actual.should] be_close(expected, delta)" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  module Rspec
4
4
  module Matchers
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  module Rspec
4
4
  module Matchers
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "should be_predicate" do
4
4
  it "should pass when actual returns true for :predicate?" do
@@ -117,27 +117,143 @@ describe "should_not be_predicate(*args)" do
117
117
  end
118
118
  end
119
119
 
120
+ describe "should be_predicate(&block)" do
121
+ it "should pass when actual returns true for :predicate?(&block)" do
122
+ actual = mock("actual")
123
+ delegate = mock("delegate")
124
+ actual.should_receive(:happy?).and_yield
125
+ delegate.should_receive(:check_happy).and_return(true)
126
+ actual.should be_happy { delegate.check_happy }
127
+ end
128
+
129
+ it "should fail when actual returns false for :predicate?(&block)" do
130
+ actual = mock("actual")
131
+ delegate = mock("delegate")
132
+ actual.should_receive(:happy?).and_yield
133
+ delegate.should_receive(:check_happy).and_return(false)
134
+ lambda {
135
+ actual.should be_happy { delegate.check_happy }
136
+ }.should fail_with("expected happy? to return true, got false")
137
+ end
138
+
139
+ it "should fail when actual does not respond to :predicate?" do
140
+ delegate = mock("delegate", :check_happy => true)
141
+ lambda {
142
+ Object.new.should be_happy { delegate.check_happy }
143
+ }.should raise_error(NameError)
144
+ end
145
+ end
146
+
147
+ describe "should_not be_predicate(&block)" do
148
+ it "should pass when actual returns false for :predicate?(&block)" do
149
+ actual = mock("actual")
150
+ delegate = mock("delegate")
151
+ actual.should_receive(:happy?).and_yield
152
+ delegate.should_receive(:check_happy).and_return(false)
153
+ actual.should_not be_happy { delegate.check_happy }
154
+ end
155
+
156
+ it "should fail when actual returns true for :predicate?(&block)" do
157
+ actual = mock("actual")
158
+ delegate = mock("delegate")
159
+ actual.should_receive(:happy?).and_yield
160
+ delegate.should_receive(:check_happy).and_return(true)
161
+ lambda {
162
+ actual.should_not be_happy { delegate.check_happy }
163
+ }.should fail_with("expected happy? to return false, got true")
164
+ end
165
+
166
+ it "should fail when actual does not respond to :predicate?" do
167
+ delegate = mock("delegate", :check_happy => true)
168
+ lambda {
169
+ Object.new.should_not be_happy { delegate.check_happy }
170
+ }.should raise_error(NameError)
171
+ end
172
+ end
173
+
174
+ describe "should be_predicate(*args, &block)" do
175
+ it "should pass when actual returns true for :predicate?(*args, &block)" do
176
+ actual = mock("actual")
177
+ delegate = mock("delegate")
178
+ actual.should_receive(:older_than?).with(3).and_yield(3)
179
+ delegate.should_receive(:check_older_than).with(3).and_return(true)
180
+ actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
181
+ end
182
+
183
+ it "should fail when actual returns false for :predicate?(*args, &block)" do
184
+ actual = mock("actual")
185
+ delegate = mock("delegate")
186
+ actual.should_receive(:older_than?).with(3).and_yield(3)
187
+ delegate.should_receive(:check_older_than).with(3).and_return(false)
188
+ lambda {
189
+ actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
190
+ }.should fail_with("expected older_than?(3) to return true, got false")
191
+ end
192
+
193
+ it "should fail when actual does not respond to :predicate?" do
194
+ delegate = mock("delegate", :check_older_than => true)
195
+ lambda {
196
+ Object.new.should be_older_than(3) { |age| delegate.check_older_than(age) }
197
+ }.should raise_error(NameError)
198
+ end
199
+ end
200
+
201
+ describe "should_not be_predicate(*args, &block)" do
202
+ it "should pass when actual returns false for :predicate?(*args, &block)" do
203
+ actual = mock("actual")
204
+ delegate = mock("delegate")
205
+ actual.should_receive(:older_than?).with(3).and_yield(3)
206
+ delegate.should_receive(:check_older_than).with(3).and_return(false)
207
+ actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
208
+ end
209
+
210
+ it "should fail when actual returns true for :predicate?(*args, &block)" do
211
+ actual = mock("actual")
212
+ delegate = mock("delegate")
213
+ actual.should_receive(:older_than?).with(3).and_yield(3)
214
+ delegate.should_receive(:check_older_than).with(3).and_return(true)
215
+ lambda {
216
+ actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
217
+ }.should fail_with("expected older_than?(3) to return false, got true")
218
+ end
219
+
220
+ it "should fail when actual does not respond to :predicate?" do
221
+ delegate = mock("delegate", :check_older_than => true)
222
+ lambda {
223
+ Object.new.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
224
+ }.should raise_error(NameError)
225
+ end
226
+ end
227
+
120
228
  describe "should be_true" do
121
- it "should pass when actual equal(true)" do
229
+ it "should pass when actual equal?(true)" do
122
230
  true.should be_true
123
231
  end
124
232
 
125
- it "should fail when actual equal(false)" do
233
+ it "should pass when actual is 1" do
234
+ 1.should be_true
235
+ end
236
+
237
+ it "should fail when actual equal?(false)" do
126
238
  lambda {
127
239
  false.should be_true
128
- }.should fail_with("expected true, got false")
240
+ }.should fail_with("expected false to be true")
129
241
  end
130
242
  end
131
243
 
132
244
  describe "should be_false" do
133
- it "should pass when actual equal(false)" do
245
+ it "should pass when actual equal?(false)" do
134
246
  false.should be_false
135
247
  end
136
248
 
137
- it "should fail when actual equal(true)" do
249
+ it "should pass when actual equal?(nil)" do
250
+ nil.should be_false
251
+ end
252
+
253
+ it "should fail when actual equal?(true)" do
138
254
  lambda {
139
255
  true.should be_false
140
- }.should fail_with("expected false, got true")
256
+ }.should fail_with("expected true to be false")
141
257
  end
142
258
  end
143
259
 
@@ -173,6 +289,10 @@ describe "should be <" do
173
289
  it "should fail when < operator returns false" do
174
290
  lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
175
291
  end
292
+
293
+ it "should describe itself" do
294
+ be.<(4).description.should == "be < 4"
295
+ end
176
296
  end
177
297
 
178
298
  describe "should be <=" do
@@ -236,17 +356,32 @@ describe "should_not with operators" do
236
356
  end
237
357
 
238
358
  describe "should be" do
239
- it "should pass if actual is true or a set value" do
359
+ it "should pass if actual is truthy" do
240
360
  true.should be
241
361
  1.should be
242
362
  end
243
363
 
244
364
  it "should fail if actual is false" do
245
- lambda {false.should be}.should fail_with("expected true, got false")
365
+ lambda {false.should be}.should fail_with("expected false to evaluate to true")
246
366
  end
247
367
 
248
368
  it "should fail if actual is nil" do
249
- lambda {nil.should be}.should fail_with("expected true, got nil")
369
+ lambda {nil.should be}.should fail_with("expected nil to evaluate to true")
370
+ end
371
+
372
+ it "should describe itself" do
373
+ be.description.should == "be"
374
+ end
375
+ end
376
+
377
+ describe "should_not be" do
378
+ it "should pass if actual is falsy" do
379
+ false.should_not be
380
+ nil.should_not be
381
+ end
382
+
383
+ it "should fail on true" do
384
+ lambda {true.should_not be}.should fail_with("expected true to evaluate to false")
250
385
  end
251
386
  end
252
387
 
@@ -254,9 +389,23 @@ describe "should be(value)" do
254
389
  it "should pass if actual.equal?(value)" do
255
390
  5.should be(5)
256
391
  end
392
+
257
393
  it "should fail if !actual.equal?(value)" do
258
394
  lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
259
395
  end
396
+
397
+ it "should describe itself" do
398
+ be(5).description.should == "be 5"
399
+ end
400
+ end
401
+
402
+ describe "should_not be(value)" do
403
+ it "should pass if !actual.equal?(value)" do
404
+ 5.should_not be(6)
405
+ end
406
+ it "should fail if !actual.equal?(value)" do
407
+ lambda { 5.should_not be(5) }.should fail_with("expected not 5, got 5")
408
+ end
260
409
  end
261
410
 
262
411
  describe "'should be' with operator" do
@@ -308,4 +457,5 @@ describe "be_an_instance_of" do
308
457
  it "fails when class is higher up hierarchy" do
309
458
  5.should_not be_an_instance_of(Numeric)
310
459
  end
311
- end
460
+ end
461
+
@@ -1,6 +1,6 @@
1
1
  #Based on patch from Wilson Bilkovich
2
2
 
3
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
+ require 'spec_helper'
4
4
  class SomethingExpected
5
5
  attr_accessor :some_value
6
6
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  Rspec::Matchers.define :have_public_instance_method do |method|
4
4
  match do |klass|
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Matchers should be able to generate their own descriptions" do
4
4
  after(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  module Rspec
4
4
  module Matchers
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module Rspec
4
+ module Matchers
5
+ describe "eq" do
6
+ it "matches when actual == expected" do
7
+ 1.should eq(1)
8
+ end
9
+
10
+ it "does not match when actual != expected" do
11
+ 1.should_not eq(2)
12
+ end
13
+
14
+ it "describes itself" do
15
+ matcher = eq(1)
16
+ matcher.matches?(1)
17
+ matcher.description.should == "== 1"
18
+ end
19
+
20
+ it "provides message, expected and actual on #failure_message" do
21
+ matcher = eq("1")
22
+ matcher.matches?(1)
23
+ matcher.failure_message_for_should.should == "\nexpected \"1\"\n got 1\n\n(compared using ==)\n"
24
+ end
25
+
26
+ it "provides message, expected and actual on #negative_failure_message" do
27
+ matcher = eq(1)
28
+ matcher.matches?(1)
29
+ matcher.failure_message_for_should_not.should == "\nexpected 1 not to equal 1\n\n(compared using ==)\n"
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  module Rspec
4
4
  module Matchers
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
  module Rspec
3
3
  module Matchers
4
4
  describe "equal" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  class Substance
4
4
  def initialize exists, description
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "should have_sym(*args)" do
4
4
  it "should pass if #has_sym?(*args) returns true" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  share_as :HaveSpecHelper do
4
4
  def create_collection_owner_with(n)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "should include(expected)" do
4
4
  it "should pass if target includes expected" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  class UnsortableObject
4
4
  def initialize(id)
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "should match(expected)" do
4
4
  it "should pass when target (String) matches expected (Regexp)" do
@@ -1,2 +1,2 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  require 'rspec/expectations/differs/default'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "should raise_error" do
4
4
  it "should pass if anything is raised" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "should respond_to(:sym)" do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "should satisfy { block }" do
4
4
  it "should pass if block returns true" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  module Rspec
4
4
  module Matchers
@@ -1,6 +1,6 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../core/lib'))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../mocks/lib'))
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ $LOAD_PATH.unshift(File.expand_path('../../../core/lib', __FILE__))
2
+ $LOAD_PATH.unshift(File.expand_path('../../../mocks/lib', __FILE__))
3
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
4
4
  require 'rspec/expectations'
5
5
  require 'rspec/mocks'
6
6
  require 'rspec/core'
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.a2
4
+ version: 2.0.0.a3
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: 2010-01-24 00:00:00 -06:00
13
+ date: 2010-02-03 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.a2
24
+ version: 2.0.0.a3
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.a2
34
+ version: 2.0.0.a3
35
35
  version:
36
36
  description:
37
37
  email: dchelimsky@gmail.com;chad.humphries@gmail.com
@@ -66,6 +66,7 @@ files:
66
66
  - lib/rspec/matchers/change.rb
67
67
  - lib/rspec/matchers/compatibility.rb
68
68
  - lib/rspec/matchers/dsl.rb
69
+ - lib/rspec/matchers/eq.rb
69
70
  - lib/rspec/matchers/eql.rb
70
71
  - lib/rspec/matchers/equal.rb
71
72
  - lib/rspec/matchers/errors.rb
@@ -98,6 +99,7 @@ files:
98
99
  - spec/rspec/matchers/compatibility_spec.rb
99
100
  - spec/rspec/matchers/description_generation_spec.rb
100
101
  - spec/rspec/matchers/dsl_spec.rb
102
+ - spec/rspec/matchers/eq_spec.rb
101
103
  - spec/rspec/matchers/eql_spec.rb
102
104
  - spec/rspec/matchers/equal_spec.rb
103
105
  - spec/rspec/matchers/exist_spec.rb
@@ -106,7 +108,6 @@ files:
106
108
  - spec/rspec/matchers/include_spec.rb
107
109
  - spec/rspec/matchers/match_array_spec.rb
108
110
  - spec/rspec/matchers/match_spec.rb
109
- - spec/rspec/matchers/matcher_methods_spec.rb
110
111
  - spec/rspec/matchers/matcher_spec.rb
111
112
  - spec/rspec/matchers/matchers_spec.rb
112
113
  - spec/rspec/matchers/operator_matcher_spec.rb
@@ -114,7 +115,6 @@ files:
114
115
  - spec/rspec/matchers/respond_to_spec.rb
115
116
  - spec/rspec/matchers/satisfy_spec.rb
116
117
  - spec/rspec/matchers/throw_symbol_spec.rb
117
- - spec/spec.opts
118
118
  - spec/spec_helper.rb
119
119
  - spec/suite.rb
120
120
  - spec/support/classes.rb
@@ -159,6 +159,7 @@ test_files:
159
159
  - spec/rspec/matchers/compatibility_spec.rb
160
160
  - spec/rspec/matchers/description_generation_spec.rb
161
161
  - spec/rspec/matchers/dsl_spec.rb
162
+ - spec/rspec/matchers/eq_spec.rb
162
163
  - spec/rspec/matchers/eql_spec.rb
163
164
  - spec/rspec/matchers/equal_spec.rb
164
165
  - spec/rspec/matchers/exist_spec.rb
@@ -167,7 +168,6 @@ test_files:
167
168
  - spec/rspec/matchers/include_spec.rb
168
169
  - spec/rspec/matchers/match_array_spec.rb
169
170
  - spec/rspec/matchers/match_spec.rb
170
- - spec/rspec/matchers/matcher_methods_spec.rb
171
171
  - spec/rspec/matchers/matcher_spec.rb
172
172
  - spec/rspec/matchers/matchers_spec.rb
173
173
  - spec/rspec/matchers/operator_matcher_spec.rb
@@ -1,63 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- module Rspec
4
- module Matchers
5
- context %Q{The Rspec::Matchers module gets included in the execution context of every spec.
6
- This module should provide the following methods, each of which returns a Matcher object.} do
7
- it "be_true" do
8
- be_true.should be_an_instance_of(Be)
9
- end
10
- it "be_false" do
11
- be_false.should be_an_instance_of(Be)
12
- end
13
- it "be_nil" do
14
- be_nil.should be_an_instance_of(Be)
15
- end
16
- it "be_arbitrary_predicate" do
17
- be_arbitrary_predicate.should be_an_instance_of(Be)
18
- end
19
- it "change" do
20
- change("target", :message).should be_an_instance_of(Change)
21
- end
22
- it "have" do
23
- have(0).should be_an_instance_of(Have)
24
- end
25
- it "have_exactly" do
26
- have_exactly(0).should be_an_instance_of(Have)
27
- end
28
- it "have_at_least" do
29
- have_at_least(0).should be_an_instance_of(Have)
30
- end
31
- it "have_at_most" do
32
- have_at_most(0).should be_an_instance_of(Have)
33
- end
34
- it "raise_error" do
35
- raise_error.should be_an_instance_of(RaiseError)
36
- raise_error(NoMethodError).should be_an_instance_of(RaiseError)
37
- raise_error(NoMethodError, "message").should be_an_instance_of(RaiseError)
38
- end
39
- it "satisfy" do
40
- satisfy{}.should be_an_instance_of(Satisfy)
41
- end
42
- it "throw_symbol" do
43
- throw_symbol.should be_an_instance_of(ThrowSymbol)
44
- throw_symbol(:sym).should be_an_instance_of(ThrowSymbol)
45
- end
46
- it "respond_to" do
47
- respond_to(:sym).should be_an_instance_of(RespondTo)
48
- end
49
- end
50
-
51
- describe "Rspec::Matchers#method_missing" do
52
- it "should convert be_xyz to Be(:be_xyz)" do
53
- Be.should_receive(:new).with(:be_whatever)
54
- be_whatever
55
- end
56
-
57
- it "should convert have_xyz to Has(:have_xyz)" do
58
- Has.should_receive(:new).with(:have_whatever)
59
- have_whatever
60
- end
61
- end
62
- end
63
- end
@@ -1,6 +0,0 @@
1
- --colour
2
- --format
3
- profile
4
- --timeout
5
- 20
6
- --diff