rspec-expectations 2.99.0.rc1 → 2.99.0

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
1
  ---
2
- SHA1:
3
- metadata.gz: 6638fae315b3f230a14e4e9a58b845016e1f2cd1
4
- data.tar.gz: 7f54fd6c65671705178edae5454c4b7c6712aac2
5
- SHA512:
6
- metadata.gz: dc9c8cc98c5d0863ba78a930e14866fed155ff606f83b96eac184ae2beeec7077d5a17613f7a49b79d7809bbf359e49289f6730ab9736ced587338769f5720bc
7
- data.tar.gz: 4cef0dcd237b8853ef730e171d333e325d141826f13e4c721a92c5e9bd71a136ea7e375c4d01d808a529dc0d209b710993ed2e949c3a3bc5e4d43b0a082ad511
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjkxOGIyZDlkOGFkYmNlNTNiZTg1NzY3MmVmZDg4ZTE2YTg1NjNlZg==
5
+ data.tar.gz: !binary |-
6
+ MDc2MmQyNGE4OWNlOTdhYTgyMDkyMDQ4MmI2NzQ1ZmRhYjhiYzE4Ng==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ODczNTI0ZjZjOWRhNzQ0Zjc5ZjVjODdjYTc1NzJjYzc1ZmM3NjQ5OGU0NDQ1
10
+ Y2MzODUzYzk5OTY1ZDI5MmY3OTlhZTRjNzJhZmQ4MzZmMzhkZWUwY2YxNTdl
11
+ ZmZiMmI1MWUzZThiOThlZWE3NDI3ZDFjMjhjZjBlM2E3OGRhYjM=
12
+ data.tar.gz: !binary |-
13
+ ODJlOTYzOGFkMjRhZTQ1OWQ5YjZhNTk4NWY0ZjZhMzhhMzk2OGRiOGNiYThl
14
+ YWFiZWNmYWJhNWVhNGJkNWEwYmViYTQ0ZjUwMTU4NmViOGE2YTQwODY3NTkz
15
+ NDQ5ZTU4M2M0MTBlMzEwMjRiNzM0Nzg3NWQzZDE0NzM3ZmU2Yzc=
data/Changelog.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 2.99.0 / 2014-06-01
2
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.99.0.rc1...v2.99.0)
3
+
4
+ Enhancements:
5
+
6
+ * Special case deprecation message for `errors_on` with `rspec-rails` to be more useful.
7
+ (Aaron Kromer)
8
+
1
9
  ### 2.99.0.rc1 / 2014-05-18
2
10
  [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.99.0.beta2...2.99.0.rc1)
3
11
 
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.99.0.rc1'
5
+ STRING = '2.99.0'
6
6
  end
7
7
  end
8
8
  end
@@ -142,19 +142,37 @@ EOF
142
142
  def print_deprecation_message(query_method)
143
143
  deprecation_message = "the rspec-collection_matchers gem "
144
144
  deprecation_message << "or replace your expectation with something like "
145
- deprecation_message << "`expect(#{cardinality_expression(query_method)}).#{expectation_format_method} #{suggested_matcher_expression}`"
145
+ if for_rspec_rails_error_on?
146
+ # It is supposed to be safe to be able to convert the args array to
147
+ # a string. This is because the `errors_on` method only takes two
148
+ # valid arguments: attribute name (symbol/string) and a hash
149
+ deprecated_call = expectation_expression(query_method, "record")
150
+ deprecated_call << "(#{errors_on_args_list})" unless @args.empty?
151
+
152
+ deprecation_message << <<-EOS.gsub(/^\s+\|/, '')
153
+ |
154
+ |
155
+ | #{record_valid_expression}
156
+ | expect(#{record_errors_expression(query_method)}).#{expectation_format_method} #{suggested_matcher_expression}
157
+ |
158
+ EOS
159
+ else
160
+ deprecated_call = expectation_expression(query_method)
161
+ deprecation_message << "`expect(#{cardinality_expression(query_method)}).#{expectation_format_method} #{suggested_matcher_expression}`"
162
+ end
146
163
 
147
- RSpec.deprecate("`#{expectation_expression(query_method)}`",
164
+ RSpec.deprecate("`#{deprecated_call}`",
148
165
  :replacement => deprecation_message,
149
166
  :type => "the have matcher"
150
167
  )
151
168
  end
152
169
 
153
- def expectation_expression(query_method)
170
+ def expectation_expression(query_method, target = nil)
171
+ target ||= target_expression
154
172
  if @negative_expectation
155
- RSpec::Expectations::Syntax.negative_expression(target_expression, original_matcher_expression)
173
+ RSpec::Expectations::Syntax.negative_expression(target, original_matcher_expression)
156
174
  else
157
- RSpec::Expectations::Syntax.positive_expression(target_expression, original_matcher_expression)
175
+ RSpec::Expectations::Syntax.positive_expression(target, original_matcher_expression)
158
176
  end
159
177
  end
160
178
 
@@ -218,6 +236,37 @@ EOF
218
236
  "have_at_least"
219
237
  end
220
238
  end
239
+
240
+ # RSpec Rails `errors_on` specific helpers
241
+ def for_rspec_rails_error_on?
242
+ defined?(RSpec::Rails) &&
243
+ /\.errors?_on\b/ =~ original_matcher_expression
244
+ end
245
+
246
+ def errors_on_args_list
247
+ list = @args.first.inspect
248
+ context = validation_context
249
+ list << ", :context => #{context}" if context
250
+ list
251
+ end
252
+
253
+ def record_valid_expression
254
+ expression = "record.valid?"
255
+ if on_context = validation_context
256
+ expression << "(#{on_context})"
257
+ end
258
+ expression
259
+ end
260
+
261
+ def validation_context
262
+ return unless Hash === @args.last
263
+ @args.last[:context].inspect
264
+ end
265
+
266
+ def record_errors_expression(query_method)
267
+ attribute = (@args.first || :attr)
268
+ "record.errors[#{attribute.inspect}].#{String(query_method)}"
269
+ end
221
270
  end
222
271
  end
223
272
  end
@@ -532,6 +532,96 @@ EOF
532
532
  end
533
533
  end
534
534
 
535
+ context "when the target is a Rails record" do
536
+ class TheModel
537
+ attr_reader :errors
538
+
539
+ def initialize(errors)
540
+ @errors = {}
541
+ @errors[:attr] = Array(errors)
542
+ end
543
+
544
+ def errors_on(attr, _ignore_opts = {})
545
+ Array(@errors[attr]).flatten.compact
546
+ end
547
+ alias_method :error_on, :errors_on
548
+ end
549
+
550
+ let(:message_preamble) do
551
+ "the rspec-collection_matchers gem " +
552
+ "or replace your expectation with something like "
553
+ end
554
+
555
+ before do
556
+ stub_const "RSpec::Rails", Module.new
557
+ end
558
+
559
+ it "prints a specific message for the positive expectation format" do
560
+ expectation_expression = "expect(record).to have(2).errors_on(:attr)"
561
+ message = message_preamble + <<-EOS.gsub(/^\s+\|/, '')
562
+ |
563
+ |
564
+ | record.valid?
565
+ | expect(record.errors[:attr].size).to eq(2)
566
+ |
567
+ EOS
568
+
569
+ expect_have_deprecation(expectation_expression, message)
570
+
571
+ target = TheModel.new(%w(foo bar))
572
+ expect(target).to have(2).errors_on(:attr)
573
+ end
574
+
575
+ it "prints a specific message for the negative expectation format" do
576
+ expectation_expression = "expect(record).not_to have(2).errors_on(:attr)"
577
+ message = message_preamble + <<-EOS.gsub(/^\s+\|/, '')
578
+ |
579
+ |
580
+ | record.valid?
581
+ | expect(record.errors[:attr].size).to_not eq(2)
582
+ |
583
+ EOS
584
+
585
+ expect_have_deprecation(expectation_expression, message)
586
+
587
+ target = TheModel.new('foo')
588
+ expect(target).not_to have(2).errors_on(:attr)
589
+ end
590
+
591
+ it "prints message for singular form: `error_on`" do
592
+ expectation_expression = "expect(record).to have(1).error_on(:attr)"
593
+ message = message_preamble + <<-EOS.gsub(/^\s+\|/, '')
594
+ |
595
+ |
596
+ | record.valid?
597
+ | expect(record.errors[:attr].size).to eq(1)
598
+ |
599
+ EOS
600
+
601
+ expect_have_deprecation(expectation_expression, message)
602
+
603
+ target = TheModel.new('foo')
604
+ expect(target).to have(1).error_on(:attr)
605
+ end
606
+
607
+ it "includes a validation context when provided" do
608
+ expectation_expression = "expect(record).to have(2).errors_on(:attr, :context => :spec)"
609
+ message = message_preamble + <<-EOS.gsub(/^\s+\|/, '')
610
+ |
611
+ |
612
+ | record.valid?(:spec)
613
+ | expect(record.errors[:attr].size).to eq(2)
614
+ |
615
+ EOS
616
+
617
+ expect_have_deprecation(expectation_expression, message)
618
+
619
+ target = TheModel.new(%w(foo bar))
620
+ options = {:context => :spec, :should_be_ignored => true}
621
+ expect(target).to have(2).errors_on(:attr, options)
622
+ end
623
+ end
624
+
535
625
  context "when the target is an enumerator" do
536
626
  it "prints a specific message for the positive expectation format" do
537
627
  target = %w[a b c].to_enum(:each)
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.99.0.rc1
4
+ version: 2.99.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -9,68 +9,68 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-18 00:00:00.000000000 Z
12
+ date: 2014-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diff-lcs
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - ! '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: 1.1.3
21
- - - "<"
21
+ - - <
22
22
  - !ruby/object:Gem::Version
23
23
  version: '2.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ">="
28
+ - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
30
  version: 1.1.3
31
- - - "<"
31
+ - - <
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rake
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 10.0.0
41
41
  type: :development
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 10.0.0
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: cucumber
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.1.9
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.1.9
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: aruba
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.5'
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.5'
76
76
  description: rspec expectations (should[_not] and matchers)
@@ -79,46 +79,6 @@ executables: []
79
79
  extensions: []
80
80
  extra_rdoc_files: []
81
81
  files:
82
- - ".document"
83
- - ".yardopts"
84
- - Changelog.md
85
- - License.txt
86
- - README.md
87
- - features/README.md
88
- - features/Upgrade.md
89
- - features/built_in_matchers/README.md
90
- - features/built_in_matchers/be.feature
91
- - features/built_in_matchers/be_within.feature
92
- - features/built_in_matchers/cover.feature
93
- - features/built_in_matchers/end_with.feature
94
- - features/built_in_matchers/equality.feature
95
- - features/built_in_matchers/exist.feature
96
- - features/built_in_matchers/expect_change.feature
97
- - features/built_in_matchers/expect_error.feature
98
- - features/built_in_matchers/have.feature
99
- - features/built_in_matchers/include.feature
100
- - features/built_in_matchers/match.feature
101
- - features/built_in_matchers/operators.feature
102
- - features/built_in_matchers/predicates.feature
103
- - features/built_in_matchers/respond_to.feature
104
- - features/built_in_matchers/satisfy.feature
105
- - features/built_in_matchers/start_with.feature
106
- - features/built_in_matchers/throw_symbol.feature
107
- - features/built_in_matchers/types.feature
108
- - features/built_in_matchers/yield.feature
109
- - features/custom_matchers/access_running_example.feature
110
- - features/custom_matchers/define_diffable_matcher.feature
111
- - features/custom_matchers/define_matcher.feature
112
- - features/custom_matchers/define_matcher_outside_rspec.feature
113
- - features/custom_matchers/define_matcher_with_fluent_interface.feature
114
- - features/customized_message.feature
115
- - features/diffing.feature
116
- - features/implicit_docstrings.feature
117
- - features/step_definitions/additional_cli_steps.rb
118
- - features/support/env.rb
119
- - features/support/rubinius.rb
120
- - features/syntax_configuration.feature
121
- - features/test_frameworks/test_unit.feature
122
82
  - lib/rspec-expectations.rb
123
83
  - lib/rspec/expectations.rb
124
84
  - lib/rspec/expectations/caller_filter.rb
@@ -170,6 +130,46 @@ files:
170
130
  - lib/rspec/matchers/operator_matcher.rb
171
131
  - lib/rspec/matchers/pretty.rb
172
132
  - lib/rspec/matchers/test_unit_integration.rb
133
+ - README.md
134
+ - License.txt
135
+ - Changelog.md
136
+ - .yardopts
137
+ - .document
138
+ - features/README.md
139
+ - features/Upgrade.md
140
+ - features/built_in_matchers/README.md
141
+ - features/built_in_matchers/be.feature
142
+ - features/built_in_matchers/be_within.feature
143
+ - features/built_in_matchers/cover.feature
144
+ - features/built_in_matchers/end_with.feature
145
+ - features/built_in_matchers/equality.feature
146
+ - features/built_in_matchers/exist.feature
147
+ - features/built_in_matchers/expect_change.feature
148
+ - features/built_in_matchers/expect_error.feature
149
+ - features/built_in_matchers/have.feature
150
+ - features/built_in_matchers/include.feature
151
+ - features/built_in_matchers/match.feature
152
+ - features/built_in_matchers/operators.feature
153
+ - features/built_in_matchers/predicates.feature
154
+ - features/built_in_matchers/respond_to.feature
155
+ - features/built_in_matchers/satisfy.feature
156
+ - features/built_in_matchers/start_with.feature
157
+ - features/built_in_matchers/throw_symbol.feature
158
+ - features/built_in_matchers/types.feature
159
+ - features/built_in_matchers/yield.feature
160
+ - features/custom_matchers/access_running_example.feature
161
+ - features/custom_matchers/define_diffable_matcher.feature
162
+ - features/custom_matchers/define_matcher.feature
163
+ - features/custom_matchers/define_matcher_outside_rspec.feature
164
+ - features/custom_matchers/define_matcher_with_fluent_interface.feature
165
+ - features/customized_message.feature
166
+ - features/diffing.feature
167
+ - features/implicit_docstrings.feature
168
+ - features/step_definitions/additional_cli_steps.rb
169
+ - features/support/env.rb
170
+ - features/support/rubinius.rb
171
+ - features/syntax_configuration.feature
172
+ - features/test_frameworks/test_unit.feature
173
173
  - spec/rspec/expectations/configuration_spec.rb
174
174
  - spec/rspec/expectations/differ_spec.rb
175
175
  - spec/rspec/expectations/expectation_target_spec.rb
@@ -222,25 +222,25 @@ licenses:
222
222
  metadata: {}
223
223
  post_install_message:
224
224
  rdoc_options:
225
- - "--charset=UTF-8"
225
+ - --charset=UTF-8
226
226
  require_paths:
227
227
  - lib
228
228
  required_ruby_version: !ruby/object:Gem::Requirement
229
229
  requirements:
230
- - - ">="
230
+ - - ! '>='
231
231
  - !ruby/object:Gem::Version
232
232
  version: '0'
233
233
  required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  requirements:
235
- - - ">"
235
+ - - ! '>='
236
236
  - !ruby/object:Gem::Version
237
- version: 1.3.1
237
+ version: '0'
238
238
  requirements: []
239
239
  rubyforge_project: rspec
240
- rubygems_version: 2.2.2
240
+ rubygems_version: 2.0.7
241
241
  signing_key:
242
242
  specification_version: 4
243
- summary: rspec-expectations-2.99.0.rc1
243
+ summary: rspec-expectations-2.99.0
244
244
  test_files:
245
245
  - features/README.md
246
246
  - features/Upgrade.md