shoulda-matchers 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -3
- data/Appraisals +3 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +69 -70
- data/MIT-LICENSE +1 -1
- data/NEWS.md +22 -4
- data/README.md +3 -1
- data/Rakefile +9 -5
- data/features/step_definitions/rails_steps.rb +7 -7
- data/features/support/env.rb +1 -1
- data/gemfiles/3.0.gemfile +1 -1
- data/gemfiles/3.0.gemfile.lock +25 -22
- data/gemfiles/3.1.gemfile +1 -1
- data/gemfiles/3.1.gemfile.lock +27 -24
- data/gemfiles/3.2.gemfile +1 -1
- data/gemfiles/3.2.gemfile.lock +56 -52
- data/lib/shoulda/matchers/action_controller.rb +3 -2
- data/lib/shoulda/matchers/action_controller/assign_to_matcher.rb +10 -8
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +2 -4
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +3 -4
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +3 -4
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +6 -6
- data/lib/shoulda/matchers/action_controller/respond_with_content_type_matcher.rb +5 -2
- data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +2 -2
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +12 -12
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -4
- data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +10 -11
- data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +121 -0
- data/lib/shoulda/matchers/action_mailer/have_sent_email_matcher.rb +7 -4
- data/lib/shoulda/matchers/active_model.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +8 -8
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +5 -4
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +0 -1
- data/lib/shoulda/matchers/active_model/helpers.rb +16 -7
- data/lib/shoulda/matchers/active_model/only_integer_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +8 -6
- data/lib/shoulda/matchers/active_model/validate_format_of_matcher.rb +19 -10
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +19 -21
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +7 -7
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -1
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +5 -5
- data/lib/shoulda/matchers/active_record/association_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +11 -7
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +5 -5
- data/lib/shoulda/matchers/active_record/query_the_database_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -3
- data/lib/shoulda/matchers/assertion_error.rb +4 -1
- data/lib/shoulda/matchers/independent/delegate_matcher.rb +17 -7
- data/lib/shoulda/matchers/integrations/rspec.rb +19 -33
- data/lib/shoulda/matchers/version.rb +1 -1
- data/shoulda-matchers.gemspec +6 -4
- data/spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb +66 -0
- data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +22 -0
- data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +42 -0
- data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +78 -0
- data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +58 -0
- data/spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb +31 -0
- data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +31 -0
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +65 -0
- data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +51 -0
- data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +153 -0
- data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +142 -0
- data/spec/shoulda/matchers/action_mailer/have_sent_email_spec.rb +324 -0
- data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +111 -0
- data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +124 -0
- data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +43 -0
- data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +74 -0
- data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +171 -0
- data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +113 -0
- data/spec/shoulda/{active_model → matchers/active_model}/exception_message_finder_spec.rb +2 -2
- data/spec/shoulda/matchers/active_model/helpers_spec.rb +158 -0
- data/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +52 -0
- data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +41 -0
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +41 -0
- data/spec/shoulda/matchers/active_model/validate_format_of_matcher_spec.rb +75 -0
- data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +73 -0
- data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +127 -0
- data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +175 -0
- data/spec/shoulda/{active_model → matchers/active_model}/validation_message_finder_spec.rb +0 -1
- data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +106 -0
- data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +534 -0
- data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +111 -0
- data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +78 -0
- data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +41 -0
- data/spec/shoulda/{active_record → matchers/active_record}/query_the_database_matcher_spec.rb +10 -10
- data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +86 -0
- data/spec/shoulda/{independent → matchers/independent}/delegate_matcher_spec.rb +55 -34
- data/spec/spec_helper.rb +1 -2
- data/spec/support/active_model_versions.rb +4 -0
- data/spec/support/activemodel_helpers.rb +19 -0
- data/spec/support/controller_builder.rb +38 -12
- data/spec/support/model_builder.rb +8 -2
- metadata +106 -98
- data/spec/fixtures/addresses.yml +0 -3
- data/spec/fixtures/friendships.yml +0 -0
- data/spec/fixtures/posts.yml +0 -5
- data/spec/fixtures/products.yml +0 -0
- data/spec/fixtures/taggings.yml +0 -0
- data/spec/fixtures/tags.yml +0 -9
- data/spec/fixtures/users.yml +0 -6
- data/spec/shoulda/action_controller/assign_to_matcher_spec.rb +0 -63
- data/spec/shoulda/action_controller/filter_param_matcher_spec.rb +0 -20
- data/spec/shoulda/action_controller/redirect_to_matcher_spec.rb +0 -40
- data/spec/shoulda/action_controller/render_template_matcher_spec.rb +0 -69
- data/spec/shoulda/action_controller/render_with_layout_matcher_spec.rb +0 -55
- data/spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb +0 -28
- data/spec/shoulda/action_controller/respond_with_matcher_spec.rb +0 -83
- data/spec/shoulda/action_controller/route_matcher_spec.rb +0 -65
- data/spec/shoulda/action_controller/set_session_matcher_spec.rb +0 -46
- data/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb +0 -130
- data/spec/shoulda/action_mailer/have_sent_email_spec.rb +0 -333
- data/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -115
- data/spec/shoulda/active_model/allow_value_matcher_spec.rb +0 -131
- data/spec/shoulda/active_model/disallow_value_matcher_spec.rb +0 -65
- data/spec/shoulda/active_model/ensure_exclusion_of_matcher_spec.rb +0 -79
- data/spec/shoulda/active_model/ensure_inclusion_of_matcher_spec.rb +0 -181
- data/spec/shoulda/active_model/ensure_length_of_matcher_spec.rb +0 -138
- data/spec/shoulda/active_model/helpers_spec.rb +0 -129
- data/spec/shoulda/active_model/only_integer_matcher_spec.rb +0 -69
- data/spec/shoulda/active_model/validate_acceptance_of_matcher_spec.rb +0 -43
- data/spec/shoulda/active_model/validate_confirmation_of_matcher_spec.rb +0 -48
- data/spec/shoulda/active_model/validate_format_of_matcher_spec.rb +0 -79
- data/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb +0 -112
- data/spec/shoulda/active_model/validate_presence_of_matcher_spec.rb +0 -135
- data/spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb +0 -154
- data/spec/shoulda/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -84
- data/spec/shoulda/active_record/association_matcher_spec.rb +0 -642
- data/spec/shoulda/active_record/have_db_column_matcher_spec.rb +0 -185
- data/spec/shoulda/active_record/have_db_index_matcher_spec.rb +0 -105
- data/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb +0 -46
- data/spec/shoulda/active_record/serialize_matcher_spec.rb +0 -81
@@ -50,11 +50,11 @@ module Shoulda
|
|
50
50
|
update_only_correct?
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
53
|
+
def failure_message_for_should
|
54
54
|
"Expected #{expectation} (#{@problem})"
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def failure_message_for_should_not
|
58
58
|
"Did not expect #{expectation}"
|
59
59
|
end
|
60
60
|
|
@@ -78,7 +78,7 @@ module Shoulda
|
|
78
78
|
if config
|
79
79
|
true
|
80
80
|
else
|
81
|
-
@problem =
|
81
|
+
@problem = 'is not declared'
|
82
82
|
false
|
83
83
|
end
|
84
84
|
end
|
@@ -129,9 +129,9 @@ module Shoulda
|
|
129
129
|
|
130
130
|
def should_or_should_not(value)
|
131
131
|
if value
|
132
|
-
|
132
|
+
'should'
|
133
133
|
else
|
134
|
-
|
134
|
+
'should not'
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
@@ -124,11 +124,11 @@ module Shoulda # :nodoc:
|
|
124
124
|
validate_correct?
|
125
125
|
end
|
126
126
|
|
127
|
-
def
|
127
|
+
def failure_message_for_should
|
128
128
|
"Expected #{expectation} (#{@missing})"
|
129
129
|
end
|
130
130
|
|
131
|
-
def
|
131
|
+
def failure_message_for_should_not
|
132
132
|
"Did not expect #{expectation}"
|
133
133
|
end
|
134
134
|
|
@@ -260,7 +260,7 @@ module Shoulda # :nodoc:
|
|
260
260
|
if !@validate && !reflection.options[:validate] || @validate == reflection.options[:validate]
|
261
261
|
true
|
262
262
|
else
|
263
|
-
@missing = "#{@name} should have #{@validate}
|
263
|
+
@missing = "#{@name} should have :validate => #{@validate}"
|
264
264
|
false
|
265
265
|
end
|
266
266
|
end
|
@@ -51,11 +51,11 @@ module Shoulda # :nodoc:
|
|
51
51
|
correct_primary?
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
54
|
+
def failure_message_for_should
|
55
55
|
"Expected #{expectation} (#{@missing})"
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
58
|
+
def failure_message_for_should_not
|
59
59
|
"Did not expect #{expectation}"
|
60
60
|
end
|
61
61
|
|
@@ -149,11 +149,11 @@ module Shoulda # :nodoc:
|
|
149
149
|
def correct_scale?
|
150
150
|
return true unless @options.key?(:scale)
|
151
151
|
|
152
|
-
if
|
152
|
+
if actual_scale.to_s == @options[:scale].to_s
|
153
153
|
true
|
154
154
|
else
|
155
|
-
@missing = "#{model_class} has a db column named #{@column} "
|
156
|
-
|
155
|
+
@missing = "#{model_class} has a db column named #{@column} "
|
156
|
+
@missing << "of scale #{actual_scale}, not #{@options[:scale]}."
|
157
157
|
false
|
158
158
|
end
|
159
159
|
end
|
@@ -166,9 +166,9 @@ module Shoulda # :nodoc:
|
|
166
166
|
else
|
167
167
|
@missing = "#{model_class} has a db column named #{@column} "
|
168
168
|
if @options[:primary]
|
169
|
-
@missing <<
|
169
|
+
@missing << 'that is not primary, but should be'
|
170
170
|
else
|
171
|
-
@missing <<
|
171
|
+
@missing << 'that is primary, but should not be'
|
172
172
|
end
|
173
173
|
false
|
174
174
|
end
|
@@ -182,6 +182,10 @@ module Shoulda # :nodoc:
|
|
182
182
|
@subject.class
|
183
183
|
end
|
184
184
|
|
185
|
+
def actual_scale
|
186
|
+
matched_column.scale
|
187
|
+
end
|
188
|
+
|
185
189
|
def expectation
|
186
190
|
expected = "#{model_class.name} to #{description}"
|
187
191
|
end
|
@@ -37,11 +37,11 @@ module Shoulda # :nodoc:
|
|
37
37
|
index_exists? && correct_unique?
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def failure_message_for_should
|
41
41
|
"Expected #{expectation} (#{@missing})"
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def failure_message_for_should_not
|
45
45
|
"Did not expect #{expectation}"
|
46
46
|
end
|
47
47
|
|
@@ -16,19 +16,19 @@ module Shoulda # :nodoc:
|
|
16
16
|
@attribute = attribute.to_s
|
17
17
|
end
|
18
18
|
|
19
|
-
attr_reader :
|
19
|
+
attr_reader :failure_message_for_should, :failure_message_for_should_not
|
20
20
|
|
21
21
|
def matches?(subject)
|
22
22
|
@subject = subject
|
23
23
|
if readonly_attributes.include?(@attribute)
|
24
|
-
@
|
24
|
+
@failure_message_for_should_not = "Did not expect #{@attribute} to be read-only"
|
25
25
|
true
|
26
26
|
else
|
27
27
|
if readonly_attributes.empty?
|
28
|
-
@
|
29
|
-
|
28
|
+
@failure_message_for_should = "#{class_name} attribute #{@attribute} " <<
|
29
|
+
'is not read-only'
|
30
30
|
else
|
31
|
-
@
|
31
|
+
@failure_message_for_should = "#{class_name} is making " <<
|
32
32
|
"#{readonly_attributes.to_a.to_sentence} " <<
|
33
33
|
"read-only, but not #{@attribute}."
|
34
34
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/deprecation'
|
2
|
+
|
1
3
|
module Shoulda # :nodoc:
|
2
4
|
module Matchers
|
3
5
|
module ActiveRecord # :nodoc:
|
@@ -20,6 +22,7 @@ module Shoulda # :nodoc:
|
|
20
22
|
|
21
23
|
class QueryTheDatabaseMatcher # :nodoc:
|
22
24
|
def initialize(times)
|
25
|
+
ActiveSupport::Deprecation.warn 'The query_the_database matcher is deprecated and will be removed in 2.0'
|
23
26
|
@queries = []
|
24
27
|
@options = {}
|
25
28
|
|
@@ -67,7 +70,7 @@ module Shoulda # :nodoc:
|
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
70
|
-
def
|
73
|
+
def failure_message_for_should
|
71
74
|
if @options.key?(:expected_query_count)
|
72
75
|
"Expected ##{@options[:method_name]} to cause #{@options[:expected_query_count]} database queries but it actually caused #{@queries.length} queries:" + friendly_queries
|
73
76
|
else
|
@@ -75,7 +78,7 @@ module Shoulda # :nodoc:
|
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
|
-
def
|
81
|
+
def failure_message_for_should_not
|
79
82
|
if @options[:expected_query_count]
|
80
83
|
"Expected ##{@options[:method_name]} to not cause #{@options[:expected_query_count]} database queries but it actually caused #{@queries.length} queries:" + friendly_queries
|
81
84
|
else
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Shoulda # :nodoc:
|
2
2
|
module Matchers
|
3
3
|
module ActiveRecord # :nodoc:
|
4
|
-
|
5
4
|
# Ensure that the field becomes serialized.
|
6
5
|
#
|
7
6
|
# Options:
|
@@ -10,6 +9,7 @@ module Shoulda # :nodoc:
|
|
10
9
|
# Example:
|
11
10
|
# it { should serialize(:details) }
|
12
11
|
# it { should serialize(:details).as(Hash) }
|
12
|
+
# it { should serialize(:details).as_instance_of(ExampleSerializer) }
|
13
13
|
#
|
14
14
|
def serialize(name)
|
15
15
|
SerializeMatcher.new(name)
|
@@ -36,11 +36,11 @@ module Shoulda # :nodoc:
|
|
36
36
|
serialization_valid? && type_valid?
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def failure_message_for_should
|
40
40
|
"Expected #{expectation} (#{@missing})"
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def failure_message_for_should_not
|
44
44
|
"Did not expect #{expectation}"
|
45
45
|
end
|
46
46
|
|
@@ -3,11 +3,14 @@ module Shoulda
|
|
3
3
|
if Gem.ruby_version >= Gem::Version.new('1.8') && Gem.ruby_version < Gem::Version.new('1.9')
|
4
4
|
require 'test/unit'
|
5
5
|
AssertionError = Test::Unit::AssertionFailedError
|
6
|
+
elsif defined?(Test::Unit::AssertionFailedError)
|
7
|
+
# Test::Unit has been loaded already, so we use it
|
8
|
+
AssertionError = Test::Unit::AssertionFailedError
|
6
9
|
elsif Gem.ruby_version >= Gem::Version.new("1.9")
|
7
10
|
require 'minitest/unit'
|
8
11
|
AssertionError = MiniTest::Assertion
|
9
12
|
else
|
10
|
-
raise
|
13
|
+
raise 'No unit test library available'
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'bourne'
|
2
|
+
require 'active_support/deprecation'
|
2
3
|
|
3
4
|
module Shoulda # :nodoc:
|
4
5
|
module Matchers
|
@@ -10,12 +11,15 @@ module Shoulda # :nodoc:
|
|
10
11
|
# it { should delegate_method(:deliver_mail).to(:mailman) }
|
11
12
|
#
|
12
13
|
# Options:
|
13
|
-
# * <tt>:as</tt> - tests that the object being delegated to is called with a certain method
|
14
|
-
#
|
14
|
+
# * <tt>:as</tt> - tests that the object being delegated to is called with a certain method
|
15
|
+
# (defaults to same name as delegating method)
|
16
|
+
# * <tt>:with_arguments</tt> - tests that the method on the object being delegated to is
|
17
|
+
# called with certain arguments
|
15
18
|
#
|
16
19
|
# Examples:
|
17
20
|
# it { should delegate_method(:deliver_mail).to(:mailman).as(:deliver_with_haste)
|
18
|
-
# it { should delegate_method(:deliver_mail).to(:mailman).
|
21
|
+
# it { should delegate_method(:deliver_mail).to(:mailman).
|
22
|
+
# with_arguments('221B Baker St.', :hastily => true) }
|
19
23
|
#
|
20
24
|
def delegate_method(delegating_method)
|
21
25
|
DelegateMatcher.new(delegating_method)
|
@@ -23,6 +27,7 @@ module Shoulda # :nodoc:
|
|
23
27
|
|
24
28
|
class DelegateMatcher
|
25
29
|
def initialize(delegating_method)
|
30
|
+
ActiveSupport::Deprecation.warn 'The delegate_method matcher is deprecated and will be removed in 2.0'
|
26
31
|
@delegating_method = delegating_method
|
27
32
|
end
|
28
33
|
|
@@ -37,12 +42,17 @@ module Shoulda # :nodoc:
|
|
37
42
|
subject.stubs(@target_method).returns(stubbed_object)
|
38
43
|
subject.send(@delegating_method)
|
39
44
|
|
40
|
-
|
41
|
-
|
45
|
+
matcher = Mocha::API::HaveReceived.new(method_on_target).with(*@delegated_arguments)
|
46
|
+
matcher.matches?(stubbed_object)
|
47
|
+
rescue NoMethodError, Mocha::ExpectationError
|
42
48
|
false
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
52
|
+
def description
|
53
|
+
add_clarifications_to("delegate method ##{@delegating_method} to :#{@target_method}")
|
54
|
+
end
|
55
|
+
|
46
56
|
def does_not_match?(subject)
|
47
57
|
raise InvalidDelegateMatcher
|
48
58
|
end
|
@@ -62,7 +72,7 @@ module Shoulda # :nodoc:
|
|
62
72
|
self
|
63
73
|
end
|
64
74
|
|
65
|
-
def
|
75
|
+
def failure_message_for_should
|
66
76
|
base = "Expected #{delegating_method_name} to delegate to #{target_method_name}"
|
67
77
|
add_clarifications_to(base)
|
68
78
|
end
|
@@ -75,7 +85,7 @@ module Shoulda # :nodoc:
|
|
75
85
|
end
|
76
86
|
|
77
87
|
if @method_on_target.present?
|
78
|
-
message << " as
|
88
|
+
message << " as ##{@method_on_target}"
|
79
89
|
end
|
80
90
|
|
81
91
|
message
|
@@ -1,42 +1,28 @@
|
|
1
1
|
# :enddoc:
|
2
|
+
require 'rspec'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
include Shoulda::Matchers::Independent
|
6
|
-
end
|
4
|
+
RSpec.configure do |config|
|
5
|
+
require 'shoulda/matchers/independent'
|
6
|
+
config.include Shoulda::Matchers::Independent
|
7
7
|
|
8
|
-
if defined?(::ActiveRecord)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
include Shoulda::Matchers::
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
module RSpec::Matchers
|
18
|
-
include Shoulda::Matchers::ActiveModel
|
8
|
+
if defined?(::ActiveRecord)
|
9
|
+
require 'shoulda/matchers/active_record'
|
10
|
+
require 'shoulda/matchers/active_model'
|
11
|
+
config.include Shoulda::Matchers::ActiveRecord
|
12
|
+
config.include Shoulda::Matchers::ActiveModel
|
13
|
+
|
14
|
+
elsif defined?(::ActiveModel)
|
15
|
+
require 'shoulda/matchers/active_model'
|
16
|
+
config.include Shoulda::Matchers::ActiveModel
|
19
17
|
end
|
20
|
-
end
|
21
18
|
|
22
|
-
if defined?(::ActionController)
|
23
|
-
|
24
|
-
|
25
|
-
module Rails
|
26
|
-
module ControllerExampleGroup
|
27
|
-
include Shoulda::Matchers::ActionController
|
28
|
-
end
|
29
|
-
end
|
19
|
+
if defined?(::ActionController)
|
20
|
+
require 'shoulda/matchers/action_controller'
|
21
|
+
config.include Shoulda::Matchers::ActionController
|
30
22
|
end
|
31
|
-
end
|
32
23
|
|
33
|
-
if defined?(::ActionMailer)
|
34
|
-
|
35
|
-
|
36
|
-
module Rails
|
37
|
-
module MailerExampleGroup
|
38
|
-
include Shoulda::Matchers::ActionMailer
|
39
|
-
end
|
40
|
-
end
|
24
|
+
if defined?(::ActionMailer)
|
25
|
+
require 'shoulda/matchers/action_mailer'
|
26
|
+
config.include Shoulda::Matchers::ActionMailer
|
41
27
|
end
|
42
28
|
end
|
data/shoulda-matchers.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = "support@thoughtbot.com"
|
11
11
|
s.homepage = "http://thoughtbot.com/community/"
|
12
12
|
s.summary = "Making tests easy on the fingers and eyes"
|
13
|
+
s.license = "MIT"
|
13
14
|
s.description = "Making tests easy on the fingers and eyes"
|
14
15
|
|
15
16
|
s.files = `git ls-files`.split("\n")
|
@@ -18,13 +19,14 @@ Gem::Specification.new do |s|
|
|
18
19
|
s.require_paths = ["lib"]
|
19
20
|
|
20
21
|
s.add_dependency('activesupport', '>= 3.0.0')
|
21
|
-
s.add_dependency('bourne', '~> 1.
|
22
|
+
s.add_dependency('bourne', '~> 1.2.0')
|
22
23
|
|
23
|
-
s.add_development_dependency('appraisal', '~> 0.4
|
24
|
+
s.add_development_dependency('appraisal', '~> 0.4')
|
24
25
|
s.add_development_dependency('aruba')
|
25
26
|
s.add_development_dependency('bundler', '~> 1.1')
|
26
|
-
s.add_development_dependency('cucumber', '~> 1.1
|
27
|
+
s.add_development_dependency('cucumber', '~> 1.1')
|
27
28
|
s.add_development_dependency('rails', '~> 3.0')
|
28
|
-
s.add_development_dependency('rake', '
|
29
|
+
s.add_development_dependency('rake', '>= 0.9.2')
|
29
30
|
s.add_development_dependency('rspec-rails', '~> 2.8.1')
|
31
|
+
s.add_development_dependency('strong_parameters')
|
30
32
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActionController::AssignToMatcher do
|
4
|
+
it 'includes the actual class in the failure message' do
|
5
|
+
define_class(:WrongClass) do
|
6
|
+
def to_s
|
7
|
+
'wrong class'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
controller = build_response { @var = WrongClass.new }
|
12
|
+
matcher = assign_to(:var).with_kind_of(Fixnum)
|
13
|
+
matcher.matches?(controller)
|
14
|
+
|
15
|
+
matcher.failure_message_for_should.should =~ /but got wrong class \(WrongClass\)$/
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'a controller that assigns to an instance variable' do
|
19
|
+
it 'accepts assigning to that variable' do
|
20
|
+
controller.should assign_to(:var)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'accepts assigning to that variable with the correct class' do
|
24
|
+
controller.should assign_to(:var).with_kind_of(String)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'rejects assigning to that variable with another class' do
|
28
|
+
controller.should_not assign_to(:var).with_kind_of(Fixnum)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'accepts assigning the correct value to that variable' do
|
32
|
+
controller.should assign_to(:var).with('value')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'rejects assigning another value to that variable' do
|
36
|
+
controller.should_not assign_to(:var).with('other')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'rejects assigning to another variable' do
|
40
|
+
controller.should_not assign_to(:other)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'accepts assigning to the same value in the test context' do
|
44
|
+
expected = 'value'
|
45
|
+
controller.should assign_to(:var).in_context(self).with { expected }
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'rejects assigning to the another value in the test context' do
|
49
|
+
expected = 'other'
|
50
|
+
controller.should_not assign_to(:var).in_context(self).with { expected }
|
51
|
+
end
|
52
|
+
|
53
|
+
def controller
|
54
|
+
build_response { @var = 'value' }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'a controller that assigns a nil value to an instance variable' do
|
59
|
+
it 'accepts assigning to that variable' do
|
60
|
+
controller = build_response do
|
61
|
+
@var = nil
|
62
|
+
end
|
63
|
+
controller.should assign_to(:var)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|