remockable 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +2 -3
  5. data/CHANGELOG.md +6 -0
  6. data/README.markdown +18 -4
  7. data/lib/remockable/active_model/allow_values_for.rb +14 -13
  8. data/lib/remockable/active_model/helpers.rb +7 -6
  9. data/lib/remockable/active_model/validate_acceptance_of.rb +9 -11
  10. data/lib/remockable/active_model/validate_confirmation_of.rb +9 -11
  11. data/lib/remockable/active_model/validate_exclusion_of.rb +9 -11
  12. data/lib/remockable/active_model/validate_format_of.rb +9 -11
  13. data/lib/remockable/active_model/validate_inclusion_of.rb +9 -11
  14. data/lib/remockable/active_model/validate_length_of.rb +32 -19
  15. data/lib/remockable/active_model/validate_numericality_of.rb +23 -12
  16. data/lib/remockable/active_model/validate_presence_of.rb +9 -11
  17. data/lib/remockable/active_record/accept_nested_attributes_for.rb +10 -13
  18. data/lib/remockable/active_record/belong_to.rb +21 -13
  19. data/lib/remockable/active_record/have_and_belong_to_many.rb +16 -13
  20. data/lib/remockable/active_record/have_column.rb +14 -11
  21. data/lib/remockable/active_record/have_default_scope.rb +38 -20
  22. data/lib/remockable/active_record/have_index.rb +12 -13
  23. data/lib/remockable/active_record/have_many.rb +22 -13
  24. data/lib/remockable/active_record/have_one.rb +21 -13
  25. data/lib/remockable/active_record/have_scope.rb +40 -25
  26. data/lib/remockable/active_record/helpers.rb +3 -0
  27. data/lib/remockable/active_record/validate_associated.rb +9 -11
  28. data/lib/remockable/active_record/validate_uniqueness_of.rb +19 -11
  29. data/lib/remockable/helpers.rb +58 -6
  30. data/lib/remockable/version.rb +1 -1
  31. data/remockable.gemspec +3 -3
  32. data/spec/active_model/allow_values_for_spec.rb +19 -13
  33. data/spec/active_model/validate_acceptance_of_spec.rb +0 -2
  34. data/spec/active_model/validate_confirmation_of_spec.rb +0 -2
  35. data/spec/active_model/validate_exclusion_of_spec.rb +7 -9
  36. data/spec/active_model/validate_format_of_spec.rb +9 -11
  37. data/spec/active_model/validate_inclusion_of_spec.rb +7 -9
  38. data/spec/active_model/validate_length_of_spec.rb +16 -18
  39. data/spec/active_model/validate_numericality_of_spec.rb +14 -16
  40. data/spec/active_model/validate_presence_of_spec.rb +0 -2
  41. data/spec/active_record/accept_nested_attributes_for_spec.rb +22 -18
  42. data/spec/active_record/belong_to_spec.rb +26 -26
  43. data/spec/active_record/have_and_belong_to_many_spec.rb +22 -20
  44. data/spec/active_record/have_column_spec.rb +32 -35
  45. data/spec/active_record/have_default_scope_spec.rb +54 -55
  46. data/spec/active_record/have_index_spec.rb +24 -27
  47. data/spec/active_record/have_many_spec.rb +10 -11
  48. data/spec/active_record/have_one_spec.rb +26 -25
  49. data/spec/active_record/have_scope_spec.rb +75 -75
  50. data/spec/active_record/validate_associated_spec.rb +11 -11
  51. data/spec/active_record/validate_uniqueness_of_spec.rb +11 -13
  52. data/spec/spec_helper.rb +2 -4
  53. data/spec/support/active_record_example_group.rb +3 -4
  54. data/spec/support/class_builder.rb +15 -11
  55. data/spec/support/shared/a_validation_matcher.rb +25 -25
  56. data/spec/support/shared/an_active_record_matcher.rb +14 -12
  57. metadata +60 -84
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee2c0d5e24fd72b1280d3919d63e2aaf3563dc4f
4
+ data.tar.gz: ca1a9717a4db8971bc24b37382751cb393929b14
5
+ SHA512:
6
+ metadata.gz: 9c8d53e66884d01edb3ac664b804a000fabff8d5544c613709bcb484e0412517f5dde27441002e41cb0c099ab4313b23d7bbf8647c0f6caf048884af2491b4a4
7
+ data.tar.gz: a0130e79de52649f5df8af42afe7020fec8b112c650fcad1962dc7d9313b95addee9d598e4037c50ffa7d4d9a0c1dc29fca5a43721d3c19025c0dfa64901c16b
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.swp
2
2
  .bundle
3
+ .rspec
3
4
  .rvmrc
4
5
  Gemfile.lock
5
6
  bin
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  script: bundle exec rspec
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
- - 1.9.3
4
+ - 2.0
5
+ - 2.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (2014-07-21)
4
+
5
+ * Support and require RSpec ~> 3.0 ([Tyler Hunt][tylerhunt])
6
+ * Improve documentation ([Olivier Lacan][olivierlacan])
7
+
3
8
  ## 0.2.1 (2013-10-18)
4
9
 
5
10
  * Require Rails ~> 4.0 ([Tyler Hunt][tylerhunt])
@@ -84,4 +89,5 @@
84
89
  * Initial release ([Tyler Hunt][tylerhunt])
85
90
 
86
91
  [jswanner]: https://github.com/jswanner
92
+ [olivierlacan]: https://github.com/olivierlacan
87
93
  [tylerhunt]: https://github.com/tylerhunt
data/README.markdown CHANGED
@@ -1,11 +1,15 @@
1
1
  # Remockable
2
2
 
3
- [![Build Status][travis-image]][travis]
3
+ [![Build Status][travis-image]][travis] [![Dependency Status][gemnasium-image]][gemnasium] [![Gem Version][rubygems-image]][rubygems]
4
4
 
5
5
  [travis]: http://travis-ci.org/tylerhunt/remockable
6
6
  [travis-image]: https://secure.travis-ci.org/tylerhunt/remockable.png
7
+ [gemnasium]: https://gemnasium.com/tylerhunt/remockable
8
+ [gemnasium-image]: https://gemnasium.com/tylerhunt/remockable.png
9
+ [rubygems]: http://badge.fury.io/rb/remockable
10
+ [rubygems-image]: https://badge.fury.io/rb/remockable.png
7
11
 
8
- A collection of RSpec 2 matchers to simplify your web app specs.
12
+ A collection of RSpec 3 matchers to simplify your web app specs.
9
13
 
10
14
  *Note:* Rails 3 support was dropped in version 0.2.
11
15
 
@@ -20,13 +24,13 @@ release of Rails 3 and 4.
20
24
  In looking at the code for Remarkable to determine the feasibility of continuing
21
25
  work on Remarkable itself, it seems clear that the scope of that project has
22
26
  outgrown its usefulness for most users. It was with this conclusion in mind that
23
- Remockable was born. It's an attempt to start with a clean slate but maintain
27
+ Remockable was born. Its an attempt to start with a clean slate but maintain
24
28
  the original goal of Remarkable in spirit.
25
29
 
26
30
 
27
31
  ## Installation
28
32
 
29
- Add this line to your application's `Gemfile`:
33
+ Add this line to your applications `Gemfile`:
30
34
 
31
35
  ``` ruby
32
36
  gem 'remockable'
@@ -74,6 +78,16 @@ The following Active Record matchers are supported:
74
78
  * `validate_associated`
75
79
  * `validate_uniqueness_of`
76
80
 
81
+ ### Options
82
+
83
+ Options may be passed to the matchers in the same way they’re passed to the
84
+ macros. For instance, when dealing with `has_many :through` associations, you
85
+ could specify the following:
86
+
87
+ ``` ruby
88
+ it { should have_many :subscriptions, through: :customers }
89
+ ```
90
+
77
91
 
78
92
  ## Contributing
79
93
 
@@ -1,32 +1,33 @@
1
1
  RSpec::Matchers.define(:allow_values_for) do |*attribute_and_values|
2
- @attribute = attribute_and_values.shift
3
- @values = attribute_and_values
2
+ def values
3
+ expected_as_array[1..-1]
4
+ end
4
5
 
5
- match_for_should do |actual|
6
- @values.all? do |value|
7
- subject.stub(@attribute).and_return(value)
6
+ match do |actual|
7
+ values.all? do |value|
8
+ allow(subject).to receive(attribute).and_return(value)
8
9
  subject.valid?
9
- subject.errors[@attribute].empty?
10
+ subject.errors[attribute].empty?
10
11
  end
11
12
  end
12
13
 
13
- match_for_should_not do |actual|
14
- @values.none? do |value|
15
- subject.stub(@attribute).and_return(value)
14
+ match_when_negated do |actual|
15
+ values.none? do |value|
16
+ allow(subject).to receive(attribute).and_return(value)
16
17
  subject.valid?
17
- subject.errors[@attribute].empty?
18
+ subject.errors[attribute].empty?
18
19
  end
19
20
  end
20
21
 
21
- failure_message_for_should do |actual|
22
+ failure_message do |actual|
22
23
  "Expected #{actual.class.name} to #{description}"
23
24
  end
24
25
 
25
- failure_message_for_should_not do |actual|
26
+ failure_message_when_negated do |actual|
26
27
  "Did not expect #{actual.class.name} to #{description}"
27
28
  end
28
29
 
29
30
  description do
30
- "allow the values #{@values.collect(&:inspect).to_sentence} for #{@attribute}"
31
+ "allow the values #{values.collect(&:inspect).to_sentence} for #{attribute}"
31
32
  end
32
33
  end
@@ -1,28 +1,29 @@
1
+ require 'active_support/concern'
2
+
1
3
  require 'remockable/helpers'
2
4
 
3
5
  module Remockable
4
6
  module ActiveModel
5
7
  module Helpers
8
+ extend ActiveSupport::Concern
6
9
  include Remockable::Helpers
7
10
 
8
11
  CONDITIONALS = [:if, :unless]
9
12
 
10
- attr_reader :type
11
-
12
13
  def validator_for(attribute)
13
14
  subject.class.validators_on(attribute).detect do |validator|
14
15
  validator.kind == type
15
16
  end
16
17
  end
17
18
 
18
- def options_match(validator, expected=expected)
19
- actual = validator.options.slice(*(expected.keys - CONDITIONALS))
20
- actual == expected.except(*CONDITIONALS)
19
+ def options_match(validator, options=options)
20
+ actual = validator.options.slice(*(options.keys - CONDITIONALS))
21
+ actual == options.except(*CONDITIONALS)
21
22
  end
22
23
 
23
24
  def conditionals_match(validator)
24
25
  CONDITIONALS.all? do |option|
25
- expected_value = expected[option]
26
+ expected_value = options[option]
26
27
 
27
28
  if !expected_value.nil? && expected_value.is_a?(Symbol)
28
29
  validator.options[option] == expected_value
@@ -1,27 +1,25 @@
1
- RSpec::Matchers.define(:validate_acceptance_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_acceptance_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :acceptance
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :acceptance
7
5
 
8
- valid_options %w(allow_nil accept if message on unless)
6
+ valid_options %i(allow_nil accept if message on unless)
9
7
 
10
8
  match do |actual|
11
- validator = validator_for(@attribute)
9
+ validator = validator_for(attribute)
12
10
  validator && options_match(validator) && conditionals_match(validator)
13
11
  end
14
12
 
15
- failure_message_for_should do |actual|
13
+ failure_message do |actual|
16
14
  "Expected #{subject.class.name} to #{description}"
17
15
  end
18
16
 
19
- failure_message_for_should_not do |actual|
17
+ failure_message_when_negated do |actual|
20
18
  "Did not expect #{subject.class.name} to #{description}"
21
19
  end
22
20
 
23
21
  description do
24
- with = " with #{expected.inspect}" if expected.any?
25
- "validate #{type} of #{@attribute}#{with}"
22
+ with = " with #{options.inspect}" if options.any?
23
+ "validate #{type} of #{attribute}#{with}"
26
24
  end
27
25
  end
@@ -1,27 +1,25 @@
1
- RSpec::Matchers.define(:validate_confirmation_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_confirmation_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :confirmation
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :confirmation
7
5
 
8
- valid_options %w(if message on unless)
6
+ valid_options %i(if message on unless)
9
7
 
10
8
  match do |actual|
11
- validator = validator_for(@attribute)
9
+ validator = validator_for(attribute)
12
10
  validator && options_match(validator) && conditionals_match(validator)
13
11
  end
14
12
 
15
- failure_message_for_should do |actual|
13
+ failure_message do |actual|
16
14
  "Expected #{subject.class.name} to #{description}"
17
15
  end
18
16
 
19
- failure_message_for_should_not do |actual|
17
+ failure_message_when_negated do |actual|
20
18
  "Did not expect #{subject.class.name} to #{description}"
21
19
  end
22
20
 
23
21
  description do
24
- with = " with #{expected.inspect}" if expected.any?
25
- "validate #{type} of #{@attribute}#{with}"
22
+ with = " with #{options.inspect}" if options.any?
23
+ "validate #{type} of #{attribute}#{with}"
26
24
  end
27
25
  end
@@ -1,27 +1,25 @@
1
- RSpec::Matchers.define(:validate_exclusion_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_exclusion_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :exclusion
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :exclusion
7
5
 
8
- valid_options %w(allow_nil allow_blank if in message on unless)
6
+ valid_options %i(allow_nil allow_blank if in message on unless)
9
7
 
10
8
  match do |actual|
11
- validator = validator_for(@attribute)
9
+ validator = validator_for(attribute)
12
10
  validator && options_match(validator) && conditionals_match(validator)
13
11
  end
14
12
 
15
- failure_message_for_should do |actual|
13
+ failure_message do |actual|
16
14
  "Expected #{subject.class.name} to #{description}"
17
15
  end
18
16
 
19
- failure_message_for_should_not do |actual|
17
+ failure_message_when_negated do |actual|
20
18
  "Did not expect #{subject.class.name} to #{description}"
21
19
  end
22
20
 
23
21
  description do
24
- with = " with #{expected.inspect}" if expected.any?
25
- "validate #{type} of #{@attribute}#{with}"
22
+ with = " with #{options.inspect}" if options.any?
23
+ "validate #{type} of #{attribute}#{with}"
26
24
  end
27
25
  end
@@ -1,27 +1,25 @@
1
- RSpec::Matchers.define(:validate_format_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_format_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :format
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :format
7
5
 
8
- valid_options %w(allow_blank allow_nil if message on unless with without)
6
+ valid_options %i(allow_blank allow_nil if message on unless with without)
9
7
 
10
8
  match do |actual|
11
- validator = validator_for(@attribute)
9
+ validator = validator_for(attribute)
12
10
  validator && options_match(validator) && conditionals_match(validator)
13
11
  end
14
12
 
15
- failure_message_for_should do |actual|
13
+ failure_message do |actual|
16
14
  "Expected #{subject.class.name} to #{description}"
17
15
  end
18
16
 
19
- failure_message_for_should_not do |actual|
17
+ failure_message_when_negated do |actual|
20
18
  "Did not expect #{subject.class.name} to #{description}"
21
19
  end
22
20
 
23
21
  description do
24
- with = " with #{expected.inspect}" if expected.any?
25
- "validate #{type} of #{@attribute}#{with}"
22
+ with = " with #{options.inspect}" if options.any?
23
+ "validate #{type} of #{attribute}#{with}"
26
24
  end
27
25
  end
@@ -1,27 +1,25 @@
1
- RSpec::Matchers.define(:validate_inclusion_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_inclusion_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :inclusion
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :inclusion
7
5
 
8
- valid_options %w(allow_nil allow_blank if in message on unless)
6
+ valid_options %i(allow_nil allow_blank if in message on unless)
9
7
 
10
8
  match do |actual|
11
- validator = validator_for(@attribute)
9
+ validator = validator_for(attribute)
12
10
  validator && options_match(validator) && conditionals_match(validator)
13
11
  end
14
12
 
15
- failure_message_for_should do |actual|
13
+ failure_message do |actual|
16
14
  "Expected #{subject.class.name} to #{description}"
17
15
  end
18
16
 
19
- failure_message_for_should_not do |actual|
17
+ failure_message_when_negated do |actual|
20
18
  "Did not expect #{subject.class.name} to #{description}"
21
19
  end
22
20
 
23
21
  description do
24
- with = " with #{expected.inspect}" if expected.any?
25
- "validate #{type} of #{@attribute}#{with}"
22
+ with = " with #{options.inspect}" if options.any?
23
+ "validate #{type} of #{attribute}#{with}"
26
24
  end
27
25
  end
@@ -1,41 +1,54 @@
1
- RSpec::Matchers.define(:validate_length_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_length_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :length
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :length
7
5
 
8
- unsupported_options %w(tokenizer)
9
- valid_options %w(allow_blank allow_nil if in is maximum message minimum on
10
- too_long too_short unless within wrong_length)
6
+ unsupported_options %i(tokenizer)
7
+
8
+ valid_options %i(
9
+ allow_blank
10
+ allow_nil
11
+ if
12
+ in
13
+ is
14
+ maximum
15
+ message
16
+ minimum
17
+ on
18
+ too_long
19
+ too_short
20
+ unless
21
+ within
22
+ wrong_length
23
+ )
11
24
 
12
25
  match do |actual|
13
- if validator = validator_for(@attribute)
14
- options_match = options_match(validator, normalized_expected)
26
+ if validator = validator_for(attribute)
27
+ options_match = options_match(validator, normalized_options)
15
28
  conditionals_match = conditionals_match(validator)
16
29
  options_match && conditionals_match
17
30
  end
18
31
  end
19
32
 
20
- def normalized_expected
21
- expected.dup.tap do |expected|
22
- if within = expected.delete(:within) || expected.delete(:in)
23
- expected[:minimum] = within.first
24
- expected[:maximum] = within.last
33
+ def normalized_options
34
+ options.dup.tap do |options|
35
+ if within = options.delete(:within) || options.delete(:in)
36
+ options[:minimum] = within.first
37
+ options[:maximum] = within.last
25
38
  end
26
39
  end
27
40
  end
28
41
 
29
- failure_message_for_should do |actual|
42
+ failure_message do |actual|
30
43
  "Expected #{subject.class.name} to #{description}"
31
44
  end
32
45
 
33
- failure_message_for_should_not do |actual|
46
+ failure_message_when_negated do |actual|
34
47
  "Did not expect #{subject.class.name} to #{description}"
35
48
  end
36
49
 
37
50
  description do
38
- with = " with #{expected.inspect}" if expected.any?
39
- "validate #{type} of #{@attribute}#{with}"
51
+ with = " with #{options.inspect}" if options.any?
52
+ "validate #{type} of #{attribute}#{with}"
40
53
  end
41
54
  end
@@ -1,28 +1,39 @@
1
- RSpec::Matchers.define(:validate_numericality_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_numericality_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :numericality
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :numericality
7
5
 
8
- valid_options %w(allow_nil equal_to even greater_than greater_than_or_equal_to
9
- if less_than less_than_or_equal_to message odd on only_integer unless)
6
+ valid_options %i(
7
+ allow_nil
8
+ equal_to
9
+ even
10
+ greater_than
11
+ greater_than_or_equal_to
12
+ if
13
+ less_than
14
+ less_than_or_equal_to
15
+ message
16
+ odd
17
+ on
18
+ only_integer
19
+ unless
20
+ )
10
21
 
11
22
  match do |actual|
12
- validator = validator_for(@attribute)
23
+ validator = validator_for(attribute)
13
24
  validator && options_match(validator) && conditionals_match(validator)
14
25
  end
15
26
 
16
- failure_message_for_should do |actual|
27
+ failure_message do |actual|
17
28
  "Expected #{subject.class.name} to #{description}"
18
29
  end
19
30
 
20
- failure_message_for_should_not do |actual|
31
+ failure_message_when_negated do |actual|
21
32
  "Did not expect #{subject.class.name} to #{description}"
22
33
  end
23
34
 
24
35
  description do
25
- with = " with #{expected.inspect}" if expected.any?
26
- "validate #{type} of #{@attribute}#{with}"
36
+ with = " with #{options.inspect}" if options.any?
37
+ "validate #{type} of #{attribute}#{with}"
27
38
  end
28
39
  end
@@ -1,27 +1,25 @@
1
- RSpec::Matchers.define(:validate_presence_of) do |*attribute|
2
- extend Remockable::ActiveModel::Helpers
1
+ RSpec::Matchers.define(:validate_presence_of) do
2
+ include Remockable::ActiveModel::Helpers
3
3
 
4
- @type = :presence
5
- @expected = attribute.extract_options!
6
- @attribute = attribute.shift
4
+ type :presence
7
5
 
8
- valid_options %w(if message on unless)
6
+ valid_options %i(if message on unless)
9
7
 
10
8
  match do |actual|
11
- validator = validator_for(@attribute)
9
+ validator = validator_for(attribute)
12
10
  validator && options_match(validator) && conditionals_match(validator)
13
11
  end
14
12
 
15
- failure_message_for_should do |actual|
13
+ failure_message do |actual|
16
14
  "Expected #{subject.class.name} to #{description}"
17
15
  end
18
16
 
19
- failure_message_for_should_not do |actual|
17
+ failure_message_when_negated do |actual|
20
18
  "Did not expect #{subject.class.name} to #{description}"
21
19
  end
22
20
 
23
21
  description do
24
- with = " with #{expected.inspect}" if expected.any?
25
- "validate #{type} of #{@attribute}#{with}"
22
+ with = " with #{options.inspect}" if options.any?
23
+ "validate #{type} of #{attribute}#{with}"
26
24
  end
27
25
  end
@@ -1,28 +1,25 @@
1
- RSpec::Matchers.define(:accept_nested_attributes_for) do |*association|
2
- extend Remockable::ActiveRecord::Helpers
1
+ RSpec::Matchers.define(:accept_nested_attributes_for) do
2
+ include Remockable::ActiveRecord::Helpers
3
3
 
4
- @expected = association.extract_options!
5
- @association = association.shift
6
-
7
- unsupported_options %w(reject_if)
8
- valid_options %w(allow_destroy limit update_only)
4
+ unsupported_options %i(reject_if)
5
+ valid_options %i(allow_destroy limit update_only)
9
6
 
10
7
  match do |actual|
11
- if options = subject.class.nested_attributes_options[@association]
12
- options.slice(*expected.keys) == expected
8
+ if actual_options = subject.class.nested_attributes_options[attribute]
9
+ actual_options.slice(*options.keys) == options
13
10
  end
14
11
  end
15
12
 
16
- failure_message_for_should do |actual|
13
+ failure_message do |actual|
17
14
  "Expected #{subject.class.name} to #{description}"
18
15
  end
19
16
 
20
- failure_message_for_should_not do |actual|
17
+ failure_message_when_negated do |actual|
21
18
  "Did not expect #{subject.class.name} to #{description}"
22
19
  end
23
20
 
24
21
  description do
25
- with = " with #{expected.inspect}" if expected.any?
26
- "accept nested attributes for #{@association}#{with}"
22
+ with = " with #{options.inspect}" if options.any?
23
+ "accept nested attributes for #{attribute}#{with}"
27
24
  end
28
25
  end
@@ -1,30 +1,38 @@
1
- RSpec::Matchers.define(:belong_to) do |*association|
2
- extend Remockable::ActiveRecord::Helpers
1
+ RSpec::Matchers.define(:belong_to) do
2
+ include Remockable::ActiveRecord::Helpers
3
3
 
4
- @expected = association.extract_options!
5
- @association = association.shift
6
-
7
- valid_options %w(class_name foreign_key foreign_type primary_key dependent
8
- counter_cache polymorphic validate autosave touch inverse_of)
4
+ valid_options %i(
5
+ autosave
6
+ class_name
7
+ counter_cache
8
+ dependent
9
+ foreign_key
10
+ foreign_type
11
+ inverse_of
12
+ polymorphic
13
+ primary_key
14
+ touch
15
+ validate
16
+ )
9
17
 
10
18
  match do |actual|
11
- if association = subject.class.reflect_on_association(@association)
19
+ if association = subject.class.reflect_on_association(attribute)
12
20
  macro_matches = association.macro == :belongs_to
13
- options_match = association.options.slice(*expected.keys) == expected
21
+ options_match = association.options.slice(*options.keys) == options
14
22
  macro_matches && options_match
15
23
  end
16
24
  end
17
25
 
18
- failure_message_for_should do |actual|
26
+ failure_message do |actual|
19
27
  "Expected #{subject.class.name} to #{description}"
20
28
  end
21
29
 
22
- failure_message_for_should_not do |actual|
30
+ failure_message_when_negated do |actual|
23
31
  "Did not expect #{subject.class.name} to #{description}"
24
32
  end
25
33
 
26
34
  description do
27
- with = " with #{expected.inspect}" if expected.any?
28
- "belong to #{@association}#{with}"
35
+ with = " with #{options.inspect}" if options.any?
36
+ "belong to #{attribute}#{with}"
29
37
  end
30
38
  end