rspec-expectations 2.14.5 → 2.99.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
- ---
2
- SHA1:
3
- metadata.gz: f05471f3e092a7949e6a65050baebd47319f3244
4
- data.tar.gz: d285c05c76c8e3185c735444436bb26f09f76900
5
- SHA512:
6
- metadata.gz: e035793f67b9d902d8afa94ede41915f39aa8bfacddf8cb1a03ed2c89d2e40ee0ecee5dc4bc8557d8ad933d9f33179a971d3cdd1bb2944cfdec12f27b0ddbb90
7
- data.tar.gz: f217c62ff802d25bde703e383e7b73deb28b9c895edc14e8576fae14db9ada4264bdd4cc8edd29372e5bb8dd37abf7ca1c21eda446d6bdea9d034b5c1017abd2
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWNiMjczZmU0MjNkMzFhOTQxYzdkNWJjZDc1MTc4MWJlZmJmODhhZA==
5
+ data.tar.gz: !binary |-
6
+ NjMyZWVhYjFmYzRkNjM5YWRiMDFhMGRmMDhmNTNlYWJhMzg3NDlmNQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzYyZDgzZjM5ODk5MjliNWI3YWE2MzY1ZmQ4YzQxNDQzOGU0ZDRiYzczZWMx
10
+ NGI5NzdjOTIwZmMyMDRkMGE2YzY2YTk2MjBiNGZlM2M5NjU4MmMzZjVhODFj
11
+ MDcxMDJhYTIwNTI4MTFlNmI4NjBkMjAxYTE1NzA4MDgwODJiODM=
12
+ data.tar.gz: !binary |-
13
+ YzA0Mzg2MzBmYzc1ZmFjNDI3YjQzOTVkMzYwNzQ1OWU1NDYwZTg3YjFhMzQy
14
+ Y2JjYWZkMzNiZDJjMDJkYmMyZDZjYmJlMmU0MTlkNmZiNDVkY2E0OTUwMmJj
15
+ MGM0ODI1ZWZmMjUxYmQzMDAzYzM1M2I3MzM3YWVjMDQ4YmIzMmM=
@@ -1,9 +1,27 @@
1
- ### 2.14.5 / 2014-02-01
2
- [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.4...v2.14.5)
1
+ ### 2.99.0.beta1 / 2013-11-07
2
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.4...v2.99.0.beta1)
3
3
 
4
- Bug fixes
4
+ Deprecations
5
5
 
6
- * Fix wrong matcher descriptions with falsey expected value (yujinakayama)
6
+ * Deprecate `have`, `have_at_least` and `have_at_most`. You can continue using those
7
+ matchers through https://github.com/rspec/rspec-collection_matchers, or
8
+ you can rewrite your expectations with something like
9
+ `expect(your_object.size).to eq(num)`. (Hugo Baraúna)
10
+ * Deprecate `be_xyz` predicate matcher when `xyz?` is a private method.
11
+ (Jon Rowe)
12
+ * Deprecate `be_true`/`be_false` in favour of `be_truthy`/`be_falsey`
13
+ (for Ruby's conditional semantics) or `be true`/`be false`
14
+ (for exact equality). (Sam Phippen)
15
+ * Deprecate calling helper methods from a custom matcher with the wrong
16
+ scope. (Myron Marston)
17
+ * `def self.foo` / `extend Helper` can be used to add macro methods
18
+ (e.g. methods that call the custom matcher DSL methods), but should
19
+ not be used to define helper methods called from within the DSL
20
+ blocks.
21
+ * `def foo` / `include Helper` is the opposite: it's for helper methods
22
+ callable from within a DSL block, but not for defining macros.
23
+ * RSpec 2.x allowed helper methods defined either way to be used for
24
+ either purpose, but RSpec 3.0 will not.
7
25
 
8
26
  ### 2.14.4 / 2013-11-06
9
27
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.3...v2.14.4)
@@ -3,101 +3,101 @@ Feature: "be" matchers
3
3
  There are several related "be" matchers:
4
4
 
5
5
  ```ruby
6
- obj.should be_true # passes if obj is truthy (not nil or false)
7
- obj.should be_false # passes if obj is falsy (nil or false)
6
+ obj.should be_truthy # passes if obj is truthy (not nil or false)
7
+ obj.should be_falsey # passes if obj is falsy (nil or false)
8
8
  obj.should be_nil # passes if obj is nil
9
9
  obj.should be # passes if obj is truthy (not nil or false)
10
10
  ```
11
11
 
12
- Scenario: be_true matcher
13
- Given a file named "be_true_spec.rb" with:
12
+ Scenario: be_truthy matcher
13
+ Given a file named "be_truthy_spec.rb" with:
14
14
  """ruby
15
- describe "be_true matcher" do
16
- specify { true.should be_true }
17
- specify { 7.should be_true }
18
- specify { "foo".should be_true }
19
- specify { nil.should_not be_true }
20
- specify { false.should_not be_true }
15
+ describe "be_truthy matcher" do
16
+ specify { true.should be_truthy }
17
+ specify { 7.should be_truthy }
18
+ specify { "foo".should be_truthy }
19
+ specify { nil.should_not be_truthy }
20
+ specify { false.should_not be_truthy }
21
21
 
22
22
  # deliberate failures
23
- specify { true.should_not be_true }
24
- specify { 7.should_not be_true }
25
- specify { "foo".should_not be_true }
26
- specify { nil.should be_true }
27
- specify { false.should be_true }
23
+ specify { true.should_not be_truthy }
24
+ specify { 7.should_not be_truthy }
25
+ specify { "foo".should_not be_truthy }
26
+ specify { nil.should be_truthy }
27
+ specify { false.should be_truthy }
28
28
  end
29
29
  """
30
- When I run `rspec be_true_spec.rb`
30
+ When I run `rspec be_truthy_spec.rb`
31
31
  Then the output should contain "10 examples, 5 failures"
32
32
  And the output should contain:
33
33
  """
34
- expected: non-true value
34
+ expected: falsey value
35
35
  got: true
36
36
  """
37
37
  And the output should contain:
38
38
  """
39
- expected: non-true value
39
+ expected: falsey value
40
40
  got: 7
41
41
  """
42
42
  And the output should contain:
43
43
  """
44
- expected: non-true value
44
+ expected: falsey value
45
45
  got: "foo"
46
46
  """
47
47
  And the output should contain:
48
48
  """
49
- expected: true value
49
+ expected: truthy value
50
50
  got: nil
51
51
  """
52
52
  And the output should contain:
53
53
  """
54
- expected: true value
54
+ expected: truthy value
55
55
  got: false
56
56
  """
57
57
 
58
- Scenario: be_false matcher
59
- Given a file named "be_false_spec.rb" with:
58
+ Scenario: be_falsey matcher
59
+ Given a file named "be_falsey_spec.rb" with:
60
60
  """ruby
61
- describe "be_false matcher" do
62
- specify { nil.should be_false }
63
- specify { false.should be_false }
64
- specify { true.should_not be_false }
65
- specify { 7.should_not be_false }
66
- specify { "foo".should_not be_false }
61
+ describe "be_falsey matcher" do
62
+ specify { nil.should be_falsey }
63
+ specify { false.should be_falsey }
64
+ specify { true.should_not be_falsey }
65
+ specify { 7.should_not be_falsey }
66
+ specify { "foo".should_not be_falsey }
67
67
 
68
68
  # deliberate failures
69
- specify { nil.should_not be_false }
70
- specify { false.should_not be_false }
71
- specify { true.should be_false }
72
- specify { 7.should be_false }
73
- specify { "foo".should be_false }
69
+ specify { nil.should_not be_falsey }
70
+ specify { false.should_not be_falsey }
71
+ specify { true.should be_falsey }
72
+ specify { 7.should be_falsey }
73
+ specify { "foo".should be_falsey }
74
74
  end
75
75
  """
76
- When I run `rspec be_false_spec.rb`
76
+ When I run `rspec be_falsey_spec.rb`
77
77
  Then the output should contain "10 examples, 5 failures"
78
78
  And the output should contain:
79
79
  """
80
- expected: non-false value
80
+ expected: truthy value
81
81
  got: nil
82
82
  """
83
83
  And the output should contain:
84
84
  """
85
- expected: non-false value
85
+ expected: truthy value
86
86
  got: false
87
87
  """
88
88
  And the output should contain:
89
89
  """
90
- expected: false value
90
+ expected: falsey value
91
91
  got: true
92
92
  """
93
93
  And the output should contain:
94
94
  """
95
- expected: false value
95
+ expected: falsey value
96
96
  got: 7
97
97
  """
98
98
  And the output should contain:
99
99
  """
100
- expected: false value
100
+ expected: falsey value
101
101
  got: "foo"
102
102
  """
103
103
 
@@ -0,0 +1,55 @@
1
+ module RSpec
2
+ # Consistent implementation for "cleaning" the caller method to strip out
3
+ # non-rspec lines. This enables errors to be reported at the call site in
4
+ # the code using the library, which is far more useful than the particular
5
+ # internal method that raised an error.
6
+ class CallerFilter
7
+
8
+ RSPEC_LIBS = %w[
9
+ core
10
+ mocks
11
+ expectations
12
+ matchers
13
+ rails
14
+ ]
15
+
16
+ ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ]
17
+
18
+ LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)}
19
+
20
+ if RUBY_VERSION >= '2.0.0'
21
+ def self.first_non_rspec_line
22
+ # `caller` is an expensive method that scales linearly with the size of
23
+ # the stack. The performance hit for fetching it in chunks is small,
24
+ # and since the target line is probably near the top of the stack, the
25
+ # overall improvement of a chunked search like this is significant.
26
+ #
27
+ # See benchmarks/caller.rb for measurements.
28
+
29
+ # Initial value here is mostly arbitrary, but is chosen to give good
30
+ # performance on the common case of creating a double.
31
+ increment = 5
32
+ i = 1
33
+ line = nil
34
+
35
+ while !line
36
+ stack = caller(i, increment)
37
+ raise "No non-lib lines in stack" unless stack
38
+
39
+ line = stack.find { |l| l !~ LIB_REGEX }
40
+
41
+ i += increment
42
+ increment *= 2 # The choice of two here is arbitrary.
43
+ end
44
+
45
+ line
46
+ end
47
+ else
48
+ # Earlier rubies do not support the two argument form of `caller`. This
49
+ # fallback is logically the same, but slower.
50
+ def self.first_non_rspec_line
51
+ caller.find { |line| line !~ LIB_REGEX }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,27 +1,15 @@
1
+ require 'rspec/expectations/caller_filter' unless defined?(::RSpec::CallerFilter)
2
+
1
3
  module RSpec
2
4
  module Expectations
3
5
  module Deprecation
4
- RSPEC_LIBS = %w[
5
- core
6
- mocks
7
- expectations
8
- matchers
9
- rails
10
- ]
11
-
12
- ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ]
13
-
14
- LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)}
15
-
16
6
  # @private
17
7
  #
18
8
  # Used internally to print deprecation warnings
19
9
  def deprecate(deprecated, options={})
20
- call_site = caller.find { |line| line !~ LIB_REGEX }
21
-
22
10
  message = "DEPRECATION: #{deprecated} is deprecated."
23
11
  message << " Use #{options[:replacement]} instead." if options[:replacement]
24
- message << " Called from #{call_site}."
12
+ message << " Called from #{CallerFilter.first_non_rspec_line}."
25
13
  warn message
26
14
  end
27
15
  end
@@ -2,8 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.14.5'
5
+ STRING = '2.99.0.beta1'
6
6
  end
7
7
  end
8
8
  end
9
-
@@ -183,24 +183,42 @@ module RSpec
183
183
  obj.respond_to?(:failure_message_for_should) || obj.respond_to?(:failure_message)
184
184
  end
185
185
 
186
- # Passes if actual is truthy (anything but false or nil)
187
186
  def be_true
188
- BuiltIn::BeTrue.new
187
+ RSpec.deprecate("`be_true`", :replacement =>
188
+ "`be_truthy` (for Ruby's conditional semantics) or " +
189
+ "`be true` (for exact `== true` equality)"
190
+ )
191
+ BuiltIn::BeTruthy.new
189
192
  end
190
193
 
191
- # Passes if actual is falsy (false or nil)
192
194
  def be_false
193
- BuiltIn::BeFalse.new
195
+ RSpec.deprecate("`be_false`", :replacement =>
196
+ "`be_falsey` (for Ruby's conditional semantics) or " +
197
+ "`be false` (for exact `== false` equality)"
198
+ )
199
+ BuiltIn::BeFalsey.new
200
+ end
201
+
202
+ # Passes if actual is truthy (anything but false or nil)
203
+ def be_truthy
204
+ BuiltIn::BeTruthy.new
194
205
  end
195
206
 
207
+ # Passes if actual is falsy (false or nil)
208
+ def be_falsey
209
+ BuiltIn::BeFalsey.new
210
+ end
211
+
212
+ alias_method :be_falsy, :be_falsey
213
+
196
214
  # Passes if actual is nil
197
215
  def be_nil
198
216
  BuiltIn::BeNil.new
199
217
  end
200
218
 
201
219
  # @example
202
- # expect(actual).to be_true
203
- # expect(actual).to be_false
220
+ # expect(actual).to be_truthy
221
+ # expect(actual).to be_falsey
204
222
  # expect(actual).to be_nil
205
223
  # expect(actual).to be_[arbitrary_predicate](*args)
206
224
  # expect(actual).not_to be_nil
@@ -4,8 +4,8 @@ module RSpec
4
4
  require 'rspec/matchers/built_in/base_matcher'
5
5
  autoload :BeAnInstanceOf, 'rspec/matchers/built_in/be_instance_of'
6
6
  autoload :Be, 'rspec/matchers/built_in/be'
7
- autoload :BeTrue, 'rspec/matchers/built_in/be'
8
- autoload :BeFalse, 'rspec/matchers/built_in/be'
7
+ autoload :BeTruthy, 'rspec/matchers/built_in/be'
8
+ autoload :BeFalsey, 'rspec/matchers/built_in/be'
9
9
  autoload :BeNil, 'rspec/matchers/built_in/be'
10
10
  autoload :BeComparedTo, 'rspec/matchers/built_in/be'
11
11
  autoload :BePredicate, 'rspec/matchers/built_in/be'
@@ -14,12 +14,10 @@ module RSpec
14
14
  class BaseMatcher
15
15
  include RSpec::Matchers::Pretty
16
16
 
17
- UNDEFINED = Object.new.freeze
18
-
19
17
  attr_reader :actual, :expected, :rescued_exception
20
18
 
21
- def initialize(expected = UNDEFINED)
22
- @expected = expected unless UNDEFINED.equal?(expected)
19
+ def initialize(expected = nil)
20
+ @expected = expected
23
21
  end
24
22
 
25
23
  def matches?(actual)
@@ -38,17 +36,17 @@ module RSpec
38
36
  end
39
37
 
40
38
  def failure_message_for_should
41
- assert_ivars :@actual
39
+ assert_ivars :@actual, :@expected
42
40
  "expected #{@actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"
43
41
  end
44
42
 
45
43
  def failure_message_for_should_not
46
- assert_ivars :@actual
44
+ assert_ivars :@actual, :@expected
47
45
  "expected #{@actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"
48
46
  end
49
47
 
50
48
  def description
51
- defined?(@expected) ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence
49
+ expected ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence
52
50
  end
53
51
 
54
52
  def diffable?
@@ -3,31 +3,31 @@ require 'rspec/matchers/dsl'
3
3
  module RSpec
4
4
  module Matchers
5
5
  module BuiltIn
6
- class BeTrue < BaseMatcher
6
+ class BeTruthy < BaseMatcher
7
7
  def match(_, actual)
8
8
  !!actual
9
9
  end
10
10
 
11
11
  def failure_message_for_should
12
- "expected: true value\n got: #{actual.inspect}"
12
+ "expected: truthy value\n got: #{actual.inspect}"
13
13
  end
14
14
 
15
15
  def failure_message_for_should_not
16
- "expected: non-true value\n got: #{actual.inspect}"
16
+ "expected: falsey value\n got: #{actual.inspect}"
17
17
  end
18
18
  end
19
19
 
20
- class BeFalse < BaseMatcher
20
+ class BeFalsey < BaseMatcher
21
21
  def match(_, actual)
22
22
  !actual
23
23
  end
24
24
 
25
25
  def failure_message_for_should
26
- "expected: false value\n got: #{actual.inspect}"
26
+ "expected: falsey value\n got: #{actual.inspect}"
27
27
  end
28
28
 
29
29
  def failure_message_for_should_not
30
- "expected: non-false value\n got: #{actual.inspect}"
30
+ "expected: truthy value\n got: #{actual.inspect}"
31
31
  end
32
32
  end
33
33
 
@@ -141,6 +141,13 @@ it is a bit confusing.
141
141
 
142
142
  def matches?(actual)
143
143
  @actual = actual
144
+
145
+ if is_private_on?( @actual )
146
+ RSpec.deprecate "matching with be_#{predicate.to_s.gsub(/\?$/,'')} on private method #{predicate}",
147
+ :replacement => "`expect(object.send(#{predicate.inspect})).to be_true` or change the method's visibility to public",
148
+ :call_site => caller(0)[3]
149
+ end
150
+
144
151
  begin
145
152
  return @result = actual.__send__(predicate, *@args, &@block)
146
153
  rescue NameError => predicate_missing_error
@@ -170,6 +177,17 @@ it is a bit confusing.
170
177
 
171
178
  private
172
179
 
180
+ # support 1.8.7
181
+ if methods.first.is_a? String
182
+ def is_private_on? actual
183
+ actual.private_methods.include? predicate.to_s
184
+ end
185
+ else
186
+ def is_private_on? actual
187
+ actual.private_methods.include? predicate
188
+ end
189
+ end
190
+
173
191
  def predicate
174
192
  "#{@expected}?".to_sym
175
193
  end