riot_rails 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -1,85 +1,109 @@
1
- class Riot::Assertion
2
- # Asserts that the body of the response equals or matches the expected expression. Expects actual to
3
- # be the controller.
4
- #
5
- # controller.renders("a bunch of html")
6
- # controller.renders(/bunch of/)
7
- assertion(:renders) do |actual, expected|
8
- actual_body = actual.response.body
9
- if (expected.kind_of?(Regexp) ? (actual_body =~ expected) : (expected == actual_body))
10
- pass
11
- else
12
- verb = expected.kind_of?(Regexp) ? "match" : "equal"
13
- fail("expected response body #{actual_body.inspect} to #{verb} #{expected.inspect}")
1
+ module RiotRails
2
+ module ActionController
3
+ # Asserts that the body of the response equals or matches the expected expression. Expects actual to
4
+ # be the controller.
5
+ #
6
+ # controller.renders("a bunch of html")
7
+ # controller.renders(/bunch of/)
8
+ class RendersMacro < Riot::AssertionMacro
9
+ register :renders
10
+
11
+ def evaluate(actual, expected)
12
+ actual_body = actual.response.body
13
+ if (expected.kind_of?(Regexp) ? (actual_body =~ expected) : (expected == actual_body))
14
+ pass
15
+ else
16
+ verb = expected.kind_of?(Regexp) ? "match" : "equal"
17
+ fail("expected response body #{actual_body.inspect} to #{verb} #{expected.inspect}")
18
+ end
19
+ end
20
+ end
21
+
22
+ # Asserts that the name you provide is the basename of the rendered template. For instance, if you
23
+ # expect the rendered template is named "foo_bar.html.haml" and you pass "foo_bar" into
24
+ # renders_template, the assertion would pass. If instead you pass "foo" into renders_template, the
25
+ # assertion will fail. Using Rails' assert_template both assertions would pass
26
+ #
27
+ # controlling :things
28
+ # controller.renders_template(:index)
29
+ # controller.renders_template("index")
30
+ # controller.renders_template("index.erb") # fails even if that's the name of the template
31
+ class RendersTemplateMacro < Riot::AssertionMacro
32
+ register :renders_template
33
+
34
+ def evaluate(actual, expected_name)
35
+ name = expected_name.to_s
36
+ actual_template_path = actual.response.rendered[:template].to_s
37
+ actual_template_name = File.basename(actual_template_path)
38
+ if actual_template_name.to_s.match(/^#{name}(\.\w+)*$/)
39
+ pass("renders template #{name.inspect}")
40
+ else
41
+ fail("expected template #{name.inspect}, not #{actual_template_path.inspect}")
42
+ end
43
+ end
14
44
  end
15
- end
16
45
 
17
- # Asserts that the name you provide is the basename of the rendered template. For instance, if you
18
- # expect the rendered template is named "foo_bar.html.haml" and you pass "foo_bar" into
19
- # renders_template, the assertion would pass. If instead you pass "foo" into renders_template, the
20
- # assertion will fail. Using Rails' assert_template both assertions would pass
21
- #
22
- # controlling :things
23
- # controller.renders_template(:index)
24
- # controller.renders_template("index")
25
- # controller.renders_template("index.erb") # fails even if that's the name of the template
26
- assertion(:renders_template) do |actual, expected_name|
27
- name = expected_name.to_s
28
- actual_template_path = actual.response.rendered[:template].to_s
29
- actual_template_name = File.basename(actual_template_path)
30
- msg = "expected template #{name.inspect}, not #{actual_template_path.inspect}"
31
- actual_template_name.to_s.match(/^#{name}(\.\w+)*$/) ? pass : fail(msg)
32
- end
46
+ # Asserts that the HTTP response code equals your expectation. You can use the symbolized form of the
47
+ # status code or the integer code itself. Not currently supporting status ranges; such as: +:success+,
48
+ # +:redirect+, etc.
49
+ #
50
+ # controller.response_code(:ok)
51
+ # controller.response_code(200)
52
+ #
53
+ # controller.response_code(:not_found)
54
+ # controller.response_code(404)
55
+ #
56
+ # # A redirect
57
+ # controller.response_code(:found)
58
+ # controller.response_code(302)
59
+ #
60
+ # See +ActionController::StatusCodes+ for the list of available codes.
61
+ class ResponseCodeMacro < Riot::AssertionMacro
62
+ register :response_code
33
63
 
34
- # Asserts that the HTTP response code equals your expectation. You can use the symbolized form of the
35
- # status code or the integer code itself. Not currently supporting status ranges; such as: +:success+,
36
- # +:redirect+, etc.
37
- #
38
- # controller.response_code(:ok)
39
- # controller.response_code(200)
40
- #
41
- # controller.response_code(:not_found)
42
- # controller.response_code(404)
43
- #
44
- # # A redirect
45
- # controller.response_code(:found)
46
- # controller.response_code(302)
47
- #
48
- # See +ActionController::StatusCodes+ for the list of available codes.
49
- assertion(:response_code) do |actual, expected_code|
50
- if expected_code.kind_of?(Symbol)
51
- expected_code = ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[expected_code]
64
+ def evaluate(actual, expected_code)
65
+ if expected_code.kind_of?(Symbol)
66
+ expected_code = ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[expected_code]
67
+ end
68
+ actual_code = actual.response.response_code
69
+ if expected_code == actual_code
70
+ pass("returns response code #{expected_code}")
71
+ else
72
+ fail("expected response code #{expected_code}, not #{actual_code}")
73
+ end
74
+ end
52
75
  end
53
- actual_code = actual.response.response_code
54
- expected_code == actual_code ? pass : fail("expected response code #{expected_code}, not #{actual_code}")
55
- end
56
76
 
57
- # Asserts that the response from an action is a redirect and that the path or URL matches your
58
- # expectations. If the response code is not in the 300s, the assertion will fail. If the reponse code
59
- # is fine, but the redirect-to path or URL do not exactly match your expectation, the assertion will
60
- # fail.
61
- #
62
- # +redirected_to+ expects you to provide your expected path in a lambda. This is so you can use named
63
- # routes, which are - as it turns out - handy. It's also what I would expect to be able to do.
64
- #
65
- # controlling :people
66
- # setup do
67
- # post :create, :person { ... }
68
- # end
69
- #
70
- # controller.redirected_to { person_path(...) }
71
- #
72
- # PS: There is a difference between saying +named_route_path+ and +named_route_url+ and Riot Rails will
73
- # be very strict (read: annoying) about it :)
74
- assertion(:redirected_to) do |actual, expected_redirect|
75
- actual_response_code = actual.response.response_code
76
- if (300...400).member?(actual_response_code)
77
- actual_redirect = actual.url_for(actual.response.redirected_to)
78
- msg = "expected to redirect to <#{expected_redirect}>, not <#{actual_redirect}>"
79
- expected_redirect == actual_redirect ? pass : fail(msg)
80
- else
81
- fail("expected response to be a redirect, but was #{actual_response_code}")
77
+ # Asserts that the response from an action is a redirect and that the path or URL matches your
78
+ # expectations. If the response code is not in the 300s, the assertion will fail. If the reponse code
79
+ # is fine, but the redirect-to path or URL do not exactly match your expectation, the assertion will
80
+ # fail.
81
+ #
82
+ # +redirected_to+ expects you to provide your expected path in a lambda. This is so you can use named
83
+ # routes, which are - as it turns out - handy. It's also what I would expect to be able to do.
84
+ #
85
+ # controlling :people
86
+ # setup do
87
+ # post :create, :person { ... }
88
+ # end
89
+ #
90
+ # controller.redirected_to { person_path(...) }
91
+ #
92
+ # PS: There is a difference between saying +named_route_path+ and +named_route_url+ and Riot Rails will
93
+ # be very strict (read: annoying) about it :)
94
+ class RedirectedToMacro < Riot::AssertionMacro
95
+ register :redirected_to
96
+ def evaluate(actual, expected_redirect)
97
+ actual_response_code = actual.response.response_code
98
+ if (300...400).member?(actual_response_code)
99
+ actual_redirect = actual.url_for(actual.response.redirected_to)
100
+ msg = "expected to redirect to <#{expected_redirect}>, not <#{actual_redirect}>"
101
+ expected_redirect == actual_redirect ? pass("redirected to #{expected_redirect}") : fail(msg)
102
+ else
103
+ fail("expected response to be a redirect, but was #{actual_response_code}")
104
+ end
105
+ end
82
106
  end
83
- end
84
107
 
85
- end # Riot::Assertion
108
+ end # ActionController
109
+ end # RiotRails
@@ -1,102 +1,158 @@
1
- class Riot::Assertion
1
+ module RiotRails
2
+ module ActiveRecord
2
3
 
3
- # An ActiveRecord assertion that expects to fail when a given attribute is validated after a nil value
4
- # is provided to it.
5
- #
6
- # context "a User" do
7
- # setup { User.new }
8
- # topic.validates_presence_of(:name)
9
- # end
10
- assertion(:validates_presence_of) do |actual, attribute|
11
- msg = "expected to validate presence of #{attribute.inspect}"
12
- error_from_writing_value(actual, attribute, nil) ? pass : fail(msg)
13
- end
4
+ class AssertionMacro < ::Riot::AssertionMacro
5
+ def error_from_writing_value(model, attribute, value)
6
+ model.write_attribute(attribute, value)
7
+ model.valid?
8
+ model.errors.on(attribute)
9
+ end
10
+ end
14
11
 
15
- # An ActiveRecord assertion that expects to pass with a given value or set of values for a given
16
- # attribute.
17
- #
18
- # context "a User" do
19
- # setup { User.new }
20
- # topic.allows_values_for :email, "a@b.cd"
21
- # topic.allows_values_for :email, "a@b.cd", "e@f.gh"
22
- # end
23
- assertion(:allows_values_for) do |actual, attribute, *values|
24
- bad_values = []
25
- values.each do |value|
26
- bad_values << value if error_from_writing_value(actual, attribute, value)
12
+ # An ActiveRecord assertion that expects to fail when a given attribute is validated after a nil value
13
+ # is provided to it.
14
+ #
15
+ # context "a User" do
16
+ # setup { User.new }
17
+ # topic.validates_presence_of(:name)
18
+ # end
19
+ class ValidatesPresenceOfMacro < AssertionMacro
20
+ register :validates_presence_of
21
+
22
+ def evaluate(actual, attribute)
23
+ if error_from_writing_value(actual, attribute, nil)
24
+ pass("validates presence of #{attribute.inspect}")
25
+ else
26
+ fail("expected to validate presence of #{attribute.inspect}")
27
+ end
28
+ end
27
29
  end
28
- msg = "expected #{attribute.inspect} to allow value(s) #{bad_values.inspect}"
29
- bad_values.empty? ? pass : fail(msg)
30
- end
31
30
 
32
- # An ActiveRecord assertion that expects to fail with a given value or set of values for a given
33
- # attribute.
34
- #
35
- # context "a User" do
36
- # setup { User.new }
37
- # topic.does_not_allow_values_for :email, "a"
38
- # topic.does_not_allow_values_for :email, "a@b", "e f@g.h"
39
- # end
40
- assertion(:does_not_allow_values_for) do |actual, attribute, *values|
41
- good_values = []
42
- values.each do |value|
43
- good_values << value unless error_from_writing_value(actual, attribute, value)
31
+ # An ActiveRecord assertion that expects to pass with a given value or set of values for a given
32
+ # attribute.
33
+ #
34
+ # context "a User" do
35
+ # setup { User.new }
36
+ # topic.allows_values_for :email, "a@b.cd"
37
+ # topic.allows_values_for :email, "a@b.cd", "e@f.gh"
38
+ # end
39
+ class AllowsValuesForMacro < AssertionMacro
40
+ register :allows_values_for
41
+
42
+ def evaluate(actual, attribute, *values)
43
+ bad_values = []
44
+ values.each do |value|
45
+ bad_values << value if error_from_writing_value(actual, attribute, value)
46
+ end
47
+ failure_msg = "expected %s to allow value(s) %s"
48
+ bad_values.empty? ? pass : fail(failure_msg % [attribute.inspect, bad_values.inspect])
49
+ end
44
50
  end
45
- msg = "expected #{attribute.inspect} not to allow value(s) #{good_values.inspect}"
46
- good_values.empty? ? pass : fail(msg)
47
- end
48
51
 
49
- # An ActiveRecord assertion that expects to fail with an attribute is not valid for record because the
50
- # value of the attribute is not unique. Requires the topic of the context to be a created record; one
51
- # that returns false for a call to +new_record?+.
52
- #
53
- # context "a User" do
54
- # setup { User.create(:email => "a@b.cde", ... ) }
55
- # topic.validates_uniqueness_of :email
56
- # end
57
- assertion(:validates_uniqueness_of) do |actual, attribute|
58
- actual_record = actual
59
- if actual_record.new_record?
60
- fail("topic is not a new record when testing uniqueness of #{attribute}")
61
- else
62
- copied_model = actual_record.class.new
63
- actual_record.attributes.each do |dup_attribute, dup_value|
64
- copied_model.write_attribute(dup_attribute, dup_value)
52
+ # An ActiveRecord assertion that expects to fail with a given value or set of values for a given
53
+ # attribute.
54
+ #
55
+ # context "a User" do
56
+ # setup { User.new }
57
+ # topic.does_not_allow_values_for :email, "a"
58
+ # topic.does_not_allow_values_for :email, "a@b", "e f@g.h"
59
+ # end
60
+ class DoesNotAllowValuesForMacro < AssertionMacro
61
+ register :does_not_allow_values_for
62
+ def evaluate(actual, attribute, *values)
63
+ good_values = []
64
+ values.each do |value|
65
+ good_values << value unless error_from_writing_value(actual, attribute, value)
66
+ end
67
+ failure_msg = "expected %s not to allow value(s) %s"
68
+ good_values.empty? ? pass : fail(failure_msg % [attribute.inspect, good_values.inspect])
65
69
  end
66
- copied_value = actual_record.read_attribute(attribute)
67
- msg = "expected to fail because #{attribute.inspect} is not unique"
68
- error_from_writing_value(copied_model, attribute, copied_value) ? pass : fail(msg)
69
70
  end
70
- end
71
71
 
72
- # An ActiveRecord assertion macro that expects to pass when a given attribute is defined as +has_many+
73
- # association. Will fail if an association is not defined for the attribute and if the association is
74
- # not +has_many.jekyll
75
- #
76
- # context "a Room" do
77
- # setup { Room.new }
78
- #
79
- # topic.has_many(:doors)
80
- # topic.has_many(:floors) # should probably fail given our current universe :)
81
- # end
82
- assertion(:has_many) do |actual, attribute|
83
- reflection = actual.class.reflect_on_association(attribute)
84
- static_msg = "expected #{attribute.inspect} to be a has_many association, but was "
85
- if reflection.nil?
86
- fail(static_msg + "not")
87
- elsif "has_many" != reflection.macro.to_s
88
- fail(static_msg + "a #{reflection.macro} instead")
89
- else
90
- pass
72
+ # An ActiveRecord assertion that expects to fail with invalid value for an attribute. Optionally, the
73
+ # error message can be provided as the exact string or as regular expression.
74
+ #
75
+ # context "a User" do
76
+ # setup { User.new }
77
+ # topic.is_invalid_when :email, "fake", "is invalid"
78
+ # topic.is_invalid_when :email, "another fake", /invalid/
79
+ # end
80
+ class IsInvalidWhenMacro < AssertionMacro
81
+ register :is_invalid_when
82
+
83
+ def evaluate(actual, attribute, value, expected_error=nil)
84
+ actual_errors = Array(error_from_writing_value(actual, attribute, value))
85
+ if actual_errors.empty?
86
+ fail("expected #{attribute.inspect} to be invalid when value is #{value.inspect}")
87
+ elsif expected_error && !has_error_message?(expected_error, actual_errors)
88
+ message = "expected %s to be invalid with error message %s"
89
+ fail(message % [attribute.inspect, expected_error.inspect])
90
+ else
91
+ pass("attribute #{attribute.inspect} is invalid")
92
+ end
93
+ end
94
+ private
95
+ def has_error_message?(expected, errors)
96
+ return true unless expected
97
+ expected.kind_of?(Regexp) ? errors.any? {|e| e =~ expected } : errors.any? {|e| e == expected }
98
+ end
91
99
  end
92
- end
93
100
 
94
- protected
101
+ # An ActiveRecord assertion that expects to fail with an attribute is not valid for record because the
102
+ # value of the attribute is not unique. Requires the topic of the context to be a created record; one
103
+ # that returns false for a call to +new_record?+.
104
+ #
105
+ # context "a User" do
106
+ # setup { User.create(:email => "a@b.cde", ... ) }
107
+ # topic.validates_uniqueness_of :email
108
+ # end
109
+ class ValidatesUniquenessOfMacro < AssertionMacro
110
+ register :validates_uniqueness_of
111
+
112
+ def evaluate(actual, attribute)
113
+ actual_record = actual
114
+ if actual_record.new_record?
115
+ fail("topic is not a new record when testing uniqueness of #{attribute.inspect}")
116
+ else
117
+ copied_model = actual_record.class.new
118
+ actual_record.attributes.each do |dup_attribute, dup_value|
119
+ copied_model.write_attribute(dup_attribute, dup_value)
120
+ end
121
+ copied_value = actual_record.read_attribute(attribute)
122
+ if error_from_writing_value(copied_model, attribute, copied_value)
123
+ pass("#{attribute.inspect} is unique")
124
+ else
125
+ fail("expected to fail because #{attribute.inspect} is not unique")
126
+ end
127
+ end
128
+ end
129
+ end
95
130
 
96
- def self.error_from_writing_value(model, attribute, value)
97
- model.write_attribute(attribute, value)
98
- model.valid?
99
- model.errors.on(attribute)
100
- end
131
+ # An ActiveRecord assertion macro that expects to pass when a given attribute is defined as +has_many+
132
+ # association. Will fail if an association is not defined for the attribute and if the association is
133
+ # not +has_many.jekyll
134
+ #
135
+ # context "a Room" do
136
+ # setup { Room.new }
137
+ #
138
+ # topic.has_many(:doors)
139
+ # topic.has_many(:floors) # should probably fail given our current universe :)
140
+ # end
141
+ class HasManyMacro < AssertionMacro
142
+ register :has_many
143
+
144
+ def evaluate(actual, attribute)
145
+ reflection = actual.class.reflect_on_association(attribute)
146
+ static_msg = "expected #{attribute.inspect} to be a has_many association, but was "
147
+ if reflection.nil?
148
+ fail(static_msg + "not")
149
+ elsif "has_many" != reflection.macro.to_s
150
+ fail(static_msg + "a #{reflection.macro} instead")
151
+ else
152
+ pass("has many #{attribute.inspect}")
153
+ end
154
+ end
155
+ end
101
156
 
102
- end # Riot::Assertion
157
+ end # ActiveRecord
158
+ end # RiotRails
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{riot_rails}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin 'Gus' Knowlden"]
12
- s.date = %q{2009-11-27}
12
+ s.date = %q{2009-12-29}
13
13
  s.description = %q{Riot specific test support for Rails apps. Protest the slow app.}
14
14
  s.email = %q{gus@gusg.us}
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,6 @@ context "A controller test" do
19
19
 
20
20
  asserts("an unknown action call") do
21
21
  get :burberry
22
- end.raises(ActionController::UnknownAction, "No action responded to burberry")
22
+ end.raises(::ActionController::UnknownAction, "No action responded to burberry")
23
23
 
24
24
  end # a controller test
@@ -14,14 +14,14 @@ context "Asserting the redirect of an action" do
14
14
  setup do
15
15
  @situation = Riot::Situation.new
16
16
  context = Riot::Context.new("redirected to") {}
17
- context.controlling(:redirected_to).last.run(@situation)
17
+ context.controlling(:redirected_to).run(@situation)
18
18
  context
19
19
  end
20
20
 
21
21
  context "when doing an actual redirect" do
22
22
  setup_for_assertion_test { get :index }
23
23
 
24
- assertion_test_passes("when expected url matches actual redirect url") do
24
+ assertion_test_passes("when expected url matches actual redirect url", "redirected to /gremlins/new") do
25
25
  topic.asserts_controller.redirected_to { new_gremlin_path }
26
26
  end
27
27
 
@@ -9,14 +9,14 @@ context "Asserting the rendered template for an action" do
9
9
  setup do
10
10
  @situation = Riot::Situation.new
11
11
  context = Riot::Context.new("rendered_template") {}
12
- context.controlling(:rendered_templates).last.run(@situation)
12
+ context.controlling(:rendered_templates).run(@situation)
13
13
  context
14
14
  end
15
15
 
16
16
  context "that rendered a template" do
17
17
  setup_for_assertion_test { get :foo_bar }
18
18
 
19
- assertion_test_passes("when rendered template name matches expectation") do
19
+ assertion_test_passes("when rendered template name matches expectation", %Q{renders template "foo_bar"}) do
20
20
  topic.asserts_controller.renders_template('foo_bar')
21
21
  end
22
22
 
@@ -29,11 +29,11 @@ context "Asserting the rendered template for an action" do
29
29
  context "that did not render a template, as was expected" do
30
30
  setup_for_assertion_test { get :text_me }
31
31
 
32
- assertion_test_passes("when providing nil as expectation") do
32
+ assertion_test_passes("when providing nil as expectation", %Q{renders template ""}) do
33
33
  topic.asserts_controller.renders_template(nil)
34
34
  end
35
35
 
36
- assertion_test_passes("when providing empty string as expectation") do
36
+ assertion_test_passes("when providing empty string as expectation", %Q{renders template ""}) do
37
37
  topic.asserts_controller.renders_template("")
38
38
  end
39
39
  end # that did not render a template, as was expected
@@ -8,8 +8,8 @@ context "Asserting the body of a response" do
8
8
  setup do
9
9
  @situation = Riot::Situation.new
10
10
  context = Riot::Context.new("renders") {}
11
- context.controlling(:renders).last.run(@situation)
12
- context.setup { get :index }.last.run(@situation)
11
+ context.controlling(:renders).run(@situation)
12
+ context.setup { get :index }.run(@situation)
13
13
  context
14
14
  end
15
15
 
@@ -10,15 +10,20 @@ context "Asserting the response status for an action" do
10
10
  setup do
11
11
  @situation = Riot::Situation.new
12
12
  context = Riot::Context.new("response status") {}
13
- context.controlling(:response_codes).last.run(@situation)
13
+ context.controlling(:response_codes).run(@situation)
14
14
  context
15
15
  end
16
16
 
17
17
  context "returning OK" do
18
18
  setup_for_assertion_test { get :ok_go }
19
19
 
20
- assertion_test_passes("when asked if :ok") { topic.asserts_controller.response_code(:ok) }
21
- assertion_test_passes("when asked if 200") { topic.asserts_controller.response_code(200) }
20
+ assertion_test_passes("when asked if :ok", "returns response code 200") do
21
+ topic.asserts_controller.response_code(:ok)
22
+ end
23
+
24
+ assertion_test_passes("when asked if 200", "returns response code 200") do
25
+ topic.asserts_controller.response_code(200)
26
+ end
22
27
 
23
28
  assertion_test_fails("when CONTINUE returned instead", %Q{expected response code 100, not 200}) do
24
29
  topic.asserts_controller.response_code(100)
@@ -27,14 +32,26 @@ context "Asserting the response status for an action" do
27
32
 
28
33
  context "that is redirecting" do
29
34
  setup_for_assertion_test { get :fffound }
30
- assertion_test_passes("when asked if :ok") { topic.asserts_controller.response_code(:found) }
31
- assertion_test_passes("when asked if 200") { topic.asserts_controller.response_code(302) }
35
+
36
+ assertion_test_passes("when asked if :found", "returns response code 302") do
37
+ topic.asserts_controller.response_code(:found)
38
+ end
39
+
40
+ assertion_test_passes("when asked if 302", "returns response code 302") do
41
+ topic.asserts_controller.response_code(302)
42
+ end
32
43
  end # that is redirecting
33
44
 
34
45
  context "that has explicit status" do
35
46
  setup_for_assertion_test { get :make_me }
36
- assertion_test_passes("when asked if :created") { topic.asserts_controller.response_code(:created) }
37
- assertion_test_passes("when asked if 202") {topic.asserts_controller.response_code(201) }
47
+
48
+ assertion_test_passes("when asked if :created", "returns response code 201") do
49
+ topic.asserts_controller.response_code(:created)
50
+ end
51
+
52
+ assertion_test_passes("when asked if 201", "returns response code 201") do
53
+ topic.asserts_controller.response_code(201)
54
+ end
38
55
  end # that has explicit status
39
56
 
40
57
  end # Asserting the status of a response
@@ -6,11 +6,11 @@ context "The allow_values_for assertion macro" do
6
6
 
7
7
  should("pass when attribute allows a value") do
8
8
  topic.allows_values_for(:email, "a@b.cd").run(Riot::Situation.new)
9
- end.equals([:pass])
9
+ end.equals([:pass, nil])
10
10
 
11
11
  should("pass when attribute allows multiple values") do
12
12
  topic.allows_values_for(:email, "a@b.cd", "e@f.gh").run(Riot::Situation.new)
13
- end.equals([:pass])
13
+ end.equals([:pass, nil])
14
14
 
15
15
  should("fail when attribute is provided a valid and an invalid value") do
16
16
  topic.allows_values_for(:email, "a", "e@f.gh").run(Riot::Situation.new)
@@ -23,13 +23,42 @@ context "The does_not_allow_values_for assertion macro" do
23
23
 
24
24
  should("pass when attribute does not allow a value") do
25
25
  topic.does_not_allow_values_for(:email, "a").run(Riot::Situation.new)
26
- end.equals([:pass])
26
+ end.equals([:pass, nil])
27
27
 
28
28
  should("pass when attribute does not allow multiple values") do
29
29
  topic.does_not_allow_values_for(:email, "a", "e").run(Riot::Situation.new)
30
- end.equals([:pass])
30
+ end.equals([:pass, nil])
31
31
 
32
32
  should("fail when attribute is provided a valid and an invalid value") do
33
33
  topic.does_not_allow_values_for(:email, "a", "e@f.gh").run(Riot::Situation.new)
34
34
  end.equals([:fail, %Q{expected :email not to allow value(s) ["e@f.gh"]}])
35
35
  end # The does_not_allow_values_for assertion macro
36
+
37
+ context "The is_invalid_when assertion macro" do
38
+ setup_test_context
39
+ setup { topic.asserts("room") { Room.new } }
40
+
41
+ should("pass when attribute is invalid") do
42
+ topic.is_invalid_when(:email, "fake").run(Riot::Situation.new)
43
+ end.equals([:pass, %Q{attribute :email is invalid}])
44
+
45
+ should("pass when error message equals one in its list of errors") do
46
+ topic.is_invalid_when(:email, "fake", "is invalid").run(Riot::Situation.new)
47
+ end.equals([:pass, %Q{attribute :email is invalid}])
48
+
49
+ should("pass when error message matches one in its list of errors") do
50
+ topic.is_invalid_when(:email, "fake", /invalid/).run(Riot::Situation.new)
51
+ end.equals([:pass, %Q{attribute :email is invalid}])
52
+
53
+ should("fail when attribute is valid") do
54
+ topic.is_invalid_when(:email, "a@b.cd", "is invalid").run(Riot::Situation.new)
55
+ end.equals([:fail, %Q{expected :email to be invalid when value is "a@b.cd"}])
56
+
57
+ should("fail when exact error message not found") do
58
+ topic.is_invalid_when(:email, "fake", "can't be blank").run(Riot::Situation.new)
59
+ end.equals([:fail, %Q{expected :email to be invalid with error message "can't be blank"}])
60
+
61
+ should("fail when error message not matched to returned errors") do
62
+ topic.is_invalid_when(:email, "fake", /blank/).run(Riot::Situation.new)
63
+ end.equals([:fail, %Q{expected :email to be invalid with error message /blank/}])
64
+ end # The is_invalid_when assertion macro
@@ -6,7 +6,7 @@ context "The has_many assertion macro" do
6
6
 
7
7
  should("pass when record has a has_many association defined for attribute") do
8
8
  topic.has_many(:doors).run(Riot::Situation.new)
9
- end.equals([:pass])
9
+ end.equals([:pass, "has many :doors"])
10
10
 
11
11
  should("fail when record does not have a has_many association defined for attribute") do
12
12
  topic.has_many(:windows).run(Riot::Situation.new)
@@ -6,7 +6,7 @@ context "The validates_presence_of assertion macro" do
6
6
 
7
7
  should("pass when attribute requires presence") do
8
8
  topic.validates_presence_of(:location).run(Riot::Situation.new)
9
- end.equals([:pass])
9
+ end.equals([:pass, "validates presence of :location"])
10
10
 
11
11
  should("fail when attribute does not require presence") do
12
12
  topic.validates_presence_of(:contents).run(Riot::Situation.new)
@@ -7,17 +7,17 @@ context "The validates_uniqueness_of assertion macro" do
7
7
  topic.asserts("room") do
8
8
  Room.new(:email => "foo@bar.baz", :foo => "what")
9
9
  end.validates_uniqueness_of(:email).run(Riot::Situation.new)
10
- end.equals([:fail, "topic is not a new record when testing uniqueness of email"])
10
+ end.equals([:fail, "topic is not a new record when testing uniqueness of :email"])
11
11
 
12
12
  should("pass with a persisted record") do
13
13
  topic.asserts("room") do
14
14
  Room.create_with_good_data(:email => "foo@bar.baz")
15
15
  end.validates_uniqueness_of(:email).run(Riot::Situation.new)
16
- end.equals([:pass])
16
+ end.equals([:pass, ":email is unique"])
17
17
 
18
18
  should("fail with a persisted record but not validating uniqueness") do
19
19
  topic.asserts("room") do
20
- Room.new(:email => "goo@car.caz")
20
+ Room.create_with_good_data(:email => "goo@car.caz")
21
21
  end.validates_uniqueness_of(:foo).run(Riot::Situation.new)
22
- end.equals([:fail, "topic is not a new record when testing uniqueness of foo"])
22
+ end.equals([:fail, "expected to fail because :foo is not unique"])
23
23
  end # The validates_uniqueness_of assertion macro
@@ -90,15 +90,15 @@ module RiotRails
90
90
 
91
91
  def setup_for_assertion_test(&block)
92
92
  setup do
93
- topic.setup(&block).last.run(@situation)
93
+ topic.setup(&block).run(@situation)
94
94
  topic
95
95
  end
96
96
  end
97
97
 
98
- def assertion_test_passes(description, &block)
98
+ def assertion_test_passes(description, success_message=nil, &block)
99
99
  should("pass #{description}") do
100
100
  instance_eval(&block).run(@situation)
101
- end.equals([:pass])
101
+ end.equals([:pass, success_message])
102
102
  end
103
103
 
104
104
  def assertion_test_fails(description, failure_message, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin 'Gus' Knowlden
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-27 00:00:00 -06:00
12
+ date: 2009-12-29 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency