riot_rails 0.0.6 → 0.0.7
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/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/riot/action_controller/assertion_macros.rb +81 -90
- data/lib/riot/action_controller/context_macros.rb +6 -6
- data/lib/riot/active_record/assertion_macros.rb +93 -98
- data/riot_rails.gemspec +6 -8
- data/test/action_controller/controller_context_test.rb +13 -56
- data/test/action_controller/redirected_to_test.rb +22 -41
- data/test/action_controller/renders_template_test.rb +27 -63
- data/test/action_controller/renders_test.rb +15 -41
- data/test/action_controller/response_status_test.rb +16 -64
- data/test/active_record/allowing_values_test.rb +33 -34
- data/test/active_record/has_many_test.rb +16 -44
- data/test/active_record/validates_presence_of_test.rb +11 -10
- data/test/active_record/validates_uniqueness_of_test.rb +18 -15
- data/test/teststrap.rb +64 -17
- metadata +4 -6
- data/test/action_controller/action_assigns_variable_test.rb +0 -0
data/Rakefile
CHANGED
@@ -32,7 +32,7 @@ begin
|
|
32
32
|
gem.email = "gus@gusg.us"
|
33
33
|
gem.homepage = "http://github.com/thumblemonks/riot_rails"
|
34
34
|
gem.authors = ["Justin 'Gus' Knowlden"]
|
35
|
-
gem.
|
35
|
+
gem.add_dependency("riot", ">= 0.10.2")
|
36
36
|
gem.add_development_dependency("activerecord", ">= 2.3.2")
|
37
37
|
end
|
38
38
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
@@ -1,94 +1,85 @@
|
|
1
|
-
|
2
|
-
|
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}")
|
14
|
+
end
|
15
|
+
end
|
3
16
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
20
33
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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]
|
52
|
+
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
|
37
56
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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}")
|
82
|
+
end
|
83
|
+
end
|
60
84
|
|
61
|
-
|
62
|
-
# expectations. If the response code is not in the 300s, the assertion will fail. If the reponse code
|
63
|
-
# is fine, but the redirect-to path or URL do not exactly match your expectation, the assertion will
|
64
|
-
# fail.
|
65
|
-
#
|
66
|
-
# +redirected_to+ expects you to provide your expected path in a block. This is so you can use named
|
67
|
-
# routes, which is - as it turns out - handy. It's also what I would expect to be able to do.
|
68
|
-
#
|
69
|
-
# controlling :people
|
70
|
-
# setup do
|
71
|
-
# post :create, :person { ... }
|
72
|
-
# end
|
73
|
-
#
|
74
|
-
# controller.redirected_to { person_path(...) }
|
75
|
-
#
|
76
|
-
# PS: There is a difference between saying +named_route_path+ and +named_route_url+ and Riot Rails will
|
77
|
-
# be very strict (read: annoying) about it :)
|
78
|
-
def redirected_to(&expectation_block)
|
79
|
-
actual_response_code = actual.response.response_code
|
80
|
-
if (300...400).member?(actual_response_code)
|
81
|
-
expected_redirect = actual.url_for(situation.instance_eval(&expectation_block))
|
82
|
-
actual_redirect = actual.url_for(actual.response.redirected_to)
|
83
|
-
msg = "expected to redirect to <#{expected_redirect}>, not <#{actual_redirect}>"
|
84
|
-
expected_redirect == actual_redirect || fail(msg)
|
85
|
-
else
|
86
|
-
fail("expected response to be a redirect, but was #{actual_response_code}")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end # AssertionMacros
|
90
|
-
|
91
|
-
end # ActionController
|
92
|
-
end # Riot
|
93
|
-
|
94
|
-
Riot::Assertion.instance_eval { include Riot::ActionController::AssertionMacros }
|
85
|
+
end # Riot::Assertion
|
@@ -28,16 +28,16 @@ module Riot #:nodoc:
|
|
28
28
|
# controlling :foos
|
29
29
|
# setup { get :index }
|
30
30
|
#
|
31
|
-
#
|
32
|
-
#
|
31
|
+
# asserts_controller.response_status(:found)
|
32
|
+
# asserts_controller.redirected_to { new_foo_path }
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
# Works the same as if you wrote the following assertions:
|
36
36
|
#
|
37
|
-
# asserts("controller") {
|
38
|
-
# asserts("controller") {
|
39
|
-
def
|
40
|
-
asserts("controller") {
|
37
|
+
# asserts("controller") { controller }.response_status(:found)
|
38
|
+
# asserts("controller") { controller }.redirected_to { new_foo_path }
|
39
|
+
def asserts_controller
|
40
|
+
asserts("controller") { controller }
|
41
41
|
end
|
42
42
|
end # ContextMacros
|
43
43
|
|
@@ -1,107 +1,102 @@
|
|
1
|
-
|
2
|
-
module ActiveRecord
|
1
|
+
class Riot::Assertion
|
3
2
|
|
4
|
-
|
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
|
5
14
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# setup { User.new }
|
23
|
-
# topic.allows_values_for :email, "a@b.cd"
|
24
|
-
# topic.allows_values_for :email, "a@b.cd", "e@f.gh"
|
25
|
-
# end
|
26
|
-
def allows_values_for(attribute, *values)
|
27
|
-
bad_values = []
|
28
|
-
values.each do |value|
|
29
|
-
bad_values << value if error_from_writing_value(actual, attribute, value)
|
30
|
-
end
|
31
|
-
msg = "expected #{attribute.inspect} to allow value(s) #{bad_values.inspect}"
|
32
|
-
fail(msg) unless bad_values.empty?
|
33
|
-
end
|
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)
|
27
|
+
end
|
28
|
+
msg = "expected #{attribute.inspect} to allow value(s) #{bad_values.inspect}"
|
29
|
+
bad_values.empty? ? pass : fail(msg)
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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)
|
44
|
+
end
|
45
|
+
msg = "expected #{attribute.inspect} not to allow value(s) #{good_values.inspect}"
|
46
|
+
good_values.empty? ? pass : fail(msg)
|
47
|
+
end
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
copied_value = actual_record.read_attribute(attribute)
|
70
|
-
msg = "expected to fail because #{attribute.inspect} is not unique"
|
71
|
-
error_from_writing_value(copied_model, attribute, copied_value) || fail(msg)
|
72
|
-
end
|
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)
|
73
65
|
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
|
+
end
|
70
|
+
end
|
74
71
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
def error_from_writing_value(model, attribute, value)
|
97
|
-
model.write_attribute(attribute, value)
|
98
|
-
model.valid?
|
99
|
-
model.errors.on(attribute)
|
100
|
-
end
|
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
|
91
|
+
end
|
92
|
+
end
|
101
93
|
|
102
|
-
|
94
|
+
protected
|
103
95
|
|
104
|
-
|
105
|
-
|
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
|
106
101
|
|
107
|
-
|
102
|
+
end # Riot::Assertion
|
data/riot_rails.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.0.7"
|
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-
|
12
|
+
s.date = %q{2009-11-27}
|
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 = [
|
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/riot/rails.rb",
|
31
31
|
"rails/init.rb",
|
32
32
|
"riot_rails.gemspec",
|
33
|
-
"test/action_controller/action_assigns_variable_test.rb",
|
34
33
|
"test/action_controller/controller_context_test.rb",
|
35
34
|
"test/action_controller/redirected_to_test.rb",
|
36
35
|
"test/action_controller/renders_template_test.rb",
|
@@ -51,8 +50,7 @@ Gem::Specification.new do |s|
|
|
51
50
|
s.rubygems_version = %q{1.3.5}
|
52
51
|
s.summary = %q{Riot specific test support for Rails apps}
|
53
52
|
s.test_files = [
|
54
|
-
"test/action_controller/
|
55
|
-
"test/action_controller/controller_context_test.rb",
|
53
|
+
"test/action_controller/controller_context_test.rb",
|
56
54
|
"test/action_controller/redirected_to_test.rb",
|
57
55
|
"test/action_controller/renders_template_test.rb",
|
58
56
|
"test/action_controller/renders_test.rb",
|
@@ -71,14 +69,14 @@ Gem::Specification.new do |s|
|
|
71
69
|
s.specification_version = 3
|
72
70
|
|
73
71
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
74
|
-
s.
|
72
|
+
s.add_runtime_dependency(%q<riot>, [">= 0.10.2"])
|
75
73
|
s.add_development_dependency(%q<activerecord>, [">= 2.3.2"])
|
76
74
|
else
|
77
|
-
s.add_dependency(%q<riot>, [">= 0.
|
75
|
+
s.add_dependency(%q<riot>, [">= 0.10.2"])
|
78
76
|
s.add_dependency(%q<activerecord>, [">= 2.3.2"])
|
79
77
|
end
|
80
78
|
else
|
81
|
-
s.add_dependency(%q<riot>, [">= 0.
|
79
|
+
s.add_dependency(%q<riot>, [">= 0.10.2"])
|
82
80
|
s.add_dependency(%q<activerecord>, [">= 2.3.2"])
|
83
81
|
end
|
84
82
|
end
|
@@ -3,65 +3,22 @@ require 'teststrap'
|
|
3
3
|
class FoosController < ActionController::Base
|
4
4
|
end
|
5
5
|
|
6
|
-
context "
|
7
|
-
|
8
|
-
setup do
|
9
|
-
@ctx = Riot::Context.new("foo", Riot::NilReport.new)
|
10
|
-
@ctx.controlling :foos
|
11
|
-
@ctx.situation
|
12
|
-
end
|
13
|
-
|
14
|
-
topic.assigns(:controller)
|
15
|
-
topic.assigns(:request)
|
16
|
-
topic.assigns(:response)
|
17
|
-
|
18
|
-
context "the assigned controller" do
|
19
|
-
setup { topic.controller }
|
20
|
-
|
21
|
-
topic.kind_of(FoosController)
|
22
|
-
|
23
|
-
should("have an empty params hash") do
|
24
|
-
topic.params
|
25
|
-
end.equals({})
|
26
|
-
|
27
|
-
should("return a test request when asking for request") do
|
28
|
-
topic.request
|
29
|
-
end.kind_of(::ActionController::TestRequest)
|
30
|
-
end # the assigned controller
|
31
|
-
|
32
|
-
context "the assigned request" do
|
33
|
-
setup { topic.request }
|
34
|
-
topic.kind_of(::ActionController::TestRequest)
|
35
|
-
end # the assigned request
|
36
|
-
|
37
|
-
context "the assigned response" do
|
38
|
-
setup { topic.response }
|
39
|
-
topic.kind_of(::ActionController::TestResponse)
|
40
|
-
end # the assigned response
|
41
|
-
|
42
|
-
context "calling controller" do
|
43
|
-
setup { @ctx.controller }
|
44
|
-
|
45
|
-
topic.kind_of(Riot::Assertion)
|
46
|
-
|
47
|
-
asserts("assertion name") { topic.description }.equals("foo asserts controller")
|
48
|
-
|
49
|
-
should("return the controller as the actual value") do
|
50
|
-
topic.actual
|
51
|
-
end.kind_of(FoosController)
|
52
|
-
end # calling controller
|
6
|
+
context "A controller test" do
|
7
|
+
controlling :foos
|
53
8
|
|
54
|
-
|
9
|
+
asserts_controller.kind_of(FoosController)
|
55
10
|
|
56
|
-
|
57
|
-
|
11
|
+
asserts("request is accessible") { request }.kind_of(::ActionController::TestRequest)
|
12
|
+
asserts("response is accessible") { response }.kind_of(::ActionController::TestResponse)
|
13
|
+
asserts("params is accessible") { controller.params }.equals({})
|
58
14
|
|
59
|
-
asserts("
|
60
|
-
asserts("
|
61
|
-
asserts("
|
62
|
-
asserts("
|
15
|
+
asserts("http method shortcut for get") { self }.respond_to(:get)
|
16
|
+
asserts("http method shortcut for post") { self }.respond_to(:post)
|
17
|
+
asserts("http method shortcut for put") { self }.respond_to(:put)
|
18
|
+
asserts("http method shortcut for delete") { self }.respond_to(:delete)
|
63
19
|
|
64
|
-
asserts
|
20
|
+
asserts("an unknown action call") do
|
65
21
|
get :burberry
|
66
22
|
end.raises(ActionController::UnknownAction, "No action responded to burberry")
|
67
|
-
|
23
|
+
|
24
|
+
end # a controller test
|
@@ -1,60 +1,41 @@
|
|
1
1
|
require 'teststrap'
|
2
2
|
|
3
3
|
class RedirectedToController < ActionController::Base
|
4
|
-
def index
|
5
|
-
|
6
|
-
end
|
4
|
+
def index
|
5
|
+
redirect_to new_gremlin_path
|
6
|
+
end
|
7
7
|
|
8
|
-
|
8
|
+
def show
|
9
|
+
render :text => ""
|
10
|
+
end
|
11
|
+
end
|
9
12
|
|
13
|
+
context "Asserting the redirect of an action" do
|
10
14
|
setup do
|
11
|
-
|
12
|
-
context.
|
15
|
+
@situation = Riot::Situation.new
|
16
|
+
context = Riot::Context.new("redirected to") {}
|
17
|
+
context.controlling(:redirected_to).last.run(@situation)
|
13
18
|
context
|
14
19
|
end
|
15
20
|
|
16
21
|
context "when doing an actual redirect" do
|
22
|
+
setup_for_assertion_test { get :index }
|
17
23
|
|
18
|
-
|
19
|
-
topic.
|
20
|
-
topic
|
24
|
+
assertion_test_passes("when expected url matches actual redirect url") do
|
25
|
+
topic.asserts_controller.redirected_to { new_gremlin_path }
|
21
26
|
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
assertion.passed?
|
28
|
+
assertion_test_fails("when expected url does not exactly match actual redirect url",
|
29
|
+
"expected to redirect to <http://test.host/gremlins/new>, not </gremlins/new>") do
|
30
|
+
topic.asserts_controller.redirected_to { new_gremlin_url }
|
27
31
|
end
|
28
|
-
|
29
|
-
context "and expected url does not match actual redirect url exactly" do
|
30
|
-
setup do
|
31
|
-
assertion = topic.controller
|
32
|
-
assertion.redirected_to { new_gremlin_url }
|
33
|
-
assertion
|
34
|
-
end
|
35
|
-
|
36
|
-
asserts("topic failed") { topic.failed? }
|
37
|
-
|
38
|
-
asserts("topic message") do
|
39
|
-
topic.result.message
|
40
|
-
end.matches(%r[expected to redirect to <http://test.host/gremlins/new>, not </gremlins/new>])
|
41
|
-
end # and expected url does not match actual redirect url exactly
|
42
|
-
|
43
32
|
end # when doing an actual redirect
|
44
33
|
|
45
34
|
context "when not actually doing a redirect" do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
assertion
|
35
|
+
setup_for_assertion_test { get :show }
|
36
|
+
assertion_test_fails("with message about expecting a redirect",
|
37
|
+
"expected response to be a redirect, but was 200") do
|
38
|
+
topic.asserts_controller.redirected_to { new_gremlin_path }
|
51
39
|
end
|
52
|
-
|
53
|
-
asserts("topic failed") { topic.failed? }
|
54
|
-
|
55
|
-
asserts("topic message") do
|
56
|
-
topic.result.message
|
57
|
-
end.matches(%r[expected response to be a redirect, but was 200])
|
58
40
|
end # when not actually doing a redirect
|
59
|
-
|
60
|
-
end # asserting the redirect of an action
|
41
|
+
end # Asserting the redirect of an action
|
@@ -5,89 +5,53 @@ class RenderedTemplatesController < ActionController::Base
|
|
5
5
|
def text_me; render :text => "blah"; end
|
6
6
|
end
|
7
7
|
|
8
|
-
context "
|
9
|
-
|
8
|
+
context "Asserting the rendered template for an action" do
|
10
9
|
setup do
|
11
|
-
|
12
|
-
context.
|
10
|
+
@situation = Riot::Situation.new
|
11
|
+
context = Riot::Context.new("rendered_template") {}
|
12
|
+
context.controlling(:rendered_templates).last.run(@situation)
|
13
13
|
context
|
14
14
|
end
|
15
15
|
|
16
16
|
context "that rendered a template" do
|
17
|
-
|
18
|
-
topic.setup { get :foo_bar }
|
19
|
-
topic
|
20
|
-
end
|
17
|
+
setup_for_assertion_test { get :foo_bar }
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
assertion.renders_template('foo_bar')
|
25
|
-
assertion.passed?
|
19
|
+
assertion_test_passes("when rendered template name matches expectation") do
|
20
|
+
topic.asserts_controller.renders_template('foo_bar')
|
26
21
|
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
assertion
|
33
|
-
end
|
34
|
-
|
35
|
-
asserts("topic failed") { topic.failed? }
|
36
|
-
|
37
|
-
asserts("topic message") do
|
38
|
-
topic.result.message
|
39
|
-
end.matches(/expected template "bar_foo", not "rendered_templates\/foo_bar.html.erb"/)
|
40
|
-
end # when rendered template does not match expectation
|
41
|
-
|
23
|
+
assertion_test_fails("when rendered template does not match expectation",
|
24
|
+
%Q{expected template "bar_foo", not "rendered_templates/foo_bar.html.erb"}) do
|
25
|
+
topic.asserts_controller.renders_template('bar_foo')
|
26
|
+
end
|
42
27
|
end # that rendered a template
|
43
28
|
|
44
|
-
context "that did not render a template as expected" do
|
45
|
-
|
46
|
-
topic.setup { get :text_me }
|
47
|
-
topic
|
48
|
-
end
|
29
|
+
context "that did not render a template, as was expected" do
|
30
|
+
setup_for_assertion_test { get :text_me }
|
49
31
|
|
50
|
-
|
51
|
-
|
52
|
-
assertion.renders_template(nil)
|
53
|
-
assertion.passed?
|
32
|
+
assertion_test_passes("when providing nil as expectation") do
|
33
|
+
topic.asserts_controller.renders_template(nil)
|
54
34
|
end
|
55
35
|
|
56
|
-
|
57
|
-
|
58
|
-
assertion.renders_template("")
|
59
|
-
assertion.passed?
|
36
|
+
assertion_test_passes("when providing empty string as expectation") do
|
37
|
+
topic.asserts_controller.renders_template("")
|
60
38
|
end
|
61
|
-
end # that did not render a template as expected
|
39
|
+
end # that did not render a template, as was expected
|
62
40
|
|
63
41
|
context "that did not render a template but expected one" do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
assertion.renders_template('text_me')
|
68
|
-
assertion
|
42
|
+
setup_for_assertion_test { get :text_me }
|
43
|
+
assertion_test_fails("with message", %Q{expected template "text_me", not ""}) do
|
44
|
+
topic.asserts_controller.renders_template('text_me')
|
69
45
|
end
|
70
|
-
|
71
|
-
asserts("topic failed") { topic.failed? }
|
72
|
-
|
73
|
-
asserts("topic message") do
|
74
|
-
topic.result.message
|
75
|
-
end.matches(/expected template "text_me", not ""/)
|
76
46
|
end # that did not render a template but expected one
|
77
47
|
|
78
48
|
context "that rendered a template with a partial match on template name" do
|
79
|
-
|
80
|
-
topic.setup { get :foo_bar }
|
81
|
-
assertion = topic.controller
|
82
|
-
assertion.renders_template('foo')
|
83
|
-
assertion
|
84
|
-
end
|
85
|
-
|
86
|
-
asserts("topic failed") { topic.failed? }
|
49
|
+
setup_for_assertion_test { get :foo_bar }
|
87
50
|
|
88
|
-
|
89
|
-
|
90
|
-
|
51
|
+
assertion_test_fails("with message",
|
52
|
+
%Q{expected template "foo", not "rendered_templates/foo_bar.html.erb"}) do
|
53
|
+
topic.asserts_controller.renders_template('foo')
|
54
|
+
end
|
91
55
|
end # that rendered a template with a partial match on template name
|
92
56
|
|
93
|
-
end #
|
57
|
+
end # Asserting the rendered template for an action
|
@@ -4,53 +4,27 @@ class RendersController < ActionController::Base
|
|
4
4
|
def index; render :text => "Yo mama"; end
|
5
5
|
end
|
6
6
|
|
7
|
-
context "
|
8
|
-
|
7
|
+
context "Asserting the body of a response" do
|
9
8
|
setup do
|
10
|
-
|
11
|
-
context.
|
12
|
-
context.
|
9
|
+
@situation = Riot::Situation.new
|
10
|
+
context = Riot::Context.new("renders") {}
|
11
|
+
context.controlling(:renders).last.run(@situation)
|
12
|
+
context.setup { get :index }.last.run(@situation)
|
13
13
|
context
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
assertion = topic.controller
|
18
|
-
assertion.renders("Yo mama")
|
19
|
-
assertion.passed?
|
20
|
-
end
|
21
|
-
|
22
|
-
context "when rendered action body does not equal expected" do
|
23
|
-
setup do
|
24
|
-
assertion = topic.controller
|
25
|
-
assertion.renders("Yo")
|
26
|
-
assertion
|
27
|
-
end
|
28
|
-
|
29
|
-
asserts("topic failed") { topic.failed? }
|
16
|
+
assertion_test_passes("when body equals expected") { topic.asserts_controller.renders("Yo mama") }
|
30
17
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end # when rendered action body does not equal expected
|
35
|
-
|
36
|
-
should "assert rendered action body matches expected" do
|
37
|
-
assertion = topic.controller
|
38
|
-
assertion.renders(/mama/)
|
39
|
-
assertion.passed?
|
18
|
+
assertion_test_fails("when rendered action body does not equal expected",
|
19
|
+
%Q{expected response body "Yo mama" to equal "Yo"}) do
|
20
|
+
topic.asserts_controller.renders("Yo")
|
40
21
|
end
|
41
22
|
|
42
|
-
|
43
|
-
setup do
|
44
|
-
assertion = topic.controller
|
45
|
-
assertion.renders(/obama/)
|
46
|
-
assertion
|
47
|
-
end
|
48
|
-
|
49
|
-
asserts("topic failed") { topic.failed? }
|
23
|
+
assertion_test_passes("when body matches expected") { topic.asserts_controller.renders(/mama/) }
|
50
24
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
25
|
+
assertion_test_fails("when rendered action body does not match expected",
|
26
|
+
%Q{expected response body "Yo mama" to match /obama/}) do
|
27
|
+
topic.asserts_controller.renders(/obama/)
|
28
|
+
end
|
55
29
|
|
56
|
-
end #
|
30
|
+
end # Asserting the body of a response
|
@@ -6,83 +6,35 @@ class ResponseCodesController < ActionController::Base
|
|
6
6
|
def make_me; render :text => "", :status => 201; end
|
7
7
|
end
|
8
8
|
|
9
|
-
context "
|
10
|
-
|
9
|
+
context "Asserting the response status for an action" do
|
11
10
|
setup do
|
12
|
-
|
13
|
-
context.
|
11
|
+
@situation = Riot::Situation.new
|
12
|
+
context = Riot::Context.new("response status") {}
|
13
|
+
context.controlling(:response_codes).last.run(@situation)
|
14
14
|
context
|
15
15
|
end
|
16
16
|
|
17
17
|
context "returning OK" do
|
18
|
-
|
19
|
-
topic.setup { get :ok_go }
|
20
|
-
topic
|
21
|
-
end
|
18
|
+
setup_for_assertion_test { get :ok_go }
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
assertion.response_code(:ok)
|
26
|
-
assertion.passed?
|
27
|
-
end
|
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) }
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
assertion.response_code(200)
|
32
|
-
assertion.passed?
|
23
|
+
assertion_test_fails("when CONTINUE returned instead", %Q{expected response code 100, not 200}) do
|
24
|
+
topic.asserts_controller.response_code(100)
|
33
25
|
end
|
34
|
-
|
35
|
-
context "but expected to return CONTINUE" do
|
36
|
-
setup do
|
37
|
-
assertion = topic.controller
|
38
|
-
assertion.response_code(100)
|
39
|
-
assertion
|
40
|
-
end
|
41
|
-
|
42
|
-
asserts("topic failed") { topic.failed? }
|
43
|
-
|
44
|
-
asserts("topic message") do
|
45
|
-
topic.result.message
|
46
|
-
end.matches(/expected response code 100, not 200/)
|
47
|
-
end # but expected to return CONTINUE
|
48
26
|
end # returning OK
|
49
27
|
|
50
28
|
context "that is redirecting" do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
should "pass when asked if :ok" do
|
57
|
-
assertion = topic.controller
|
58
|
-
assertion.response_code(:found)
|
59
|
-
assertion.passed?
|
60
|
-
end
|
61
|
-
|
62
|
-
should "pass when asked if 200" do
|
63
|
-
assertion = topic.controller
|
64
|
-
assertion.response_code(302)
|
65
|
-
assertion.passed?
|
66
|
-
end
|
29
|
+
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) }
|
67
32
|
end # that is redirecting
|
68
33
|
|
69
34
|
context "that has explicit status" do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
should "pass when asked if :created" do
|
76
|
-
assertion = topic.controller
|
77
|
-
assertion.response_code(:created)
|
78
|
-
assertion.passed?
|
79
|
-
end
|
80
|
-
|
81
|
-
should "pass when asked if 202" do
|
82
|
-
assertion = topic.controller
|
83
|
-
assertion.response_code(201)
|
84
|
-
assertion.passed?
|
85
|
-
end
|
35
|
+
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) }
|
86
38
|
end # that has explicit status
|
87
39
|
|
88
|
-
end #
|
40
|
+
end # Asserting the status of a response
|
@@ -1,36 +1,35 @@
|
|
1
1
|
require 'teststrap'
|
2
2
|
|
3
|
-
context "
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end #
|
19
|
-
|
20
|
-
context "does_not_allow_values_for" do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end # does_not_allow_values_for
|
3
|
+
context "The allow_values_for assertion macro" do
|
4
|
+
setup_test_context
|
5
|
+
setup { topic.asserts("room") { Room.new } }
|
6
|
+
|
7
|
+
should("pass when attribute allows a value") do
|
8
|
+
topic.allows_values_for(:email, "a@b.cd").run(Riot::Situation.new)
|
9
|
+
end.equals([:pass])
|
10
|
+
|
11
|
+
should("pass when attribute allows multiple values") do
|
12
|
+
topic.allows_values_for(:email, "a@b.cd", "e@f.gh").run(Riot::Situation.new)
|
13
|
+
end.equals([:pass])
|
14
|
+
|
15
|
+
should("fail when attribute is provided a valid and an invalid value") do
|
16
|
+
topic.allows_values_for(:email, "a", "e@f.gh").run(Riot::Situation.new)
|
17
|
+
end.equals([:fail, %Q{expected :email to allow value(s) ["a"]}])
|
18
|
+
end # The allow_values_for assertion macro
|
19
|
+
|
20
|
+
context "The does_not_allow_values_for assertion macro" do
|
21
|
+
setup_test_context
|
22
|
+
setup { topic.asserts("room") { Room.new } }
|
23
|
+
|
24
|
+
should("pass when attribute does not allow a value") do
|
25
|
+
topic.does_not_allow_values_for(:email, "a").run(Riot::Situation.new)
|
26
|
+
end.equals([:pass])
|
27
|
+
|
28
|
+
should("pass when attribute does not allow multiple values") do
|
29
|
+
topic.does_not_allow_values_for(:email, "a", "e").run(Riot::Situation.new)
|
30
|
+
end.equals([:pass])
|
31
|
+
|
32
|
+
should("fail when attribute is provided a valid and an invalid value") do
|
33
|
+
topic.does_not_allow_values_for(:email, "a", "e@f.gh").run(Riot::Situation.new)
|
34
|
+
end.equals([:fail, %Q{expected :email not to allow value(s) ["e@f.gh"]}])
|
35
|
+
end # The does_not_allow_values_for assertion macro
|
@@ -1,46 +1,18 @@
|
|
1
1
|
require 'teststrap'
|
2
2
|
|
3
|
-
context "
|
4
|
-
|
5
|
-
setup
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
context "when record does not have a has_many association defined for attribute" do
|
21
|
-
setup do
|
22
|
-
topic.has_many(:windows)
|
23
|
-
topic
|
24
|
-
end
|
25
|
-
|
26
|
-
asserts("assertion failed") { topic.failed? }
|
27
|
-
|
28
|
-
asserts("failure message") do
|
29
|
-
topic.result.message
|
30
|
-
end.matches(/expected :windows to be a has_many association, but was not/)
|
31
|
-
end # when record does not have a has_many association defined for attribute
|
32
|
-
|
33
|
-
context "when attribute is not a has_many, but is a has_one association" do
|
34
|
-
setup do
|
35
|
-
topic.has_many(:floor)
|
36
|
-
topic
|
37
|
-
end
|
38
|
-
|
39
|
-
asserts("assertion failed") { topic.failed? }
|
40
|
-
|
41
|
-
asserts("failure message") do
|
42
|
-
topic.result.message
|
43
|
-
end.matches(/expected :floor to be a has_many association, but was a has_one instead/)
|
44
|
-
end # when attribute is not a has_many, but is a has_one association
|
45
|
-
|
46
|
-
end # testing has_many
|
3
|
+
context "The has_many assertion macro" do
|
4
|
+
setup_test_context
|
5
|
+
setup { topic.asserts("room") { Room.new } }
|
6
|
+
|
7
|
+
should("pass when record has a has_many association defined for attribute") do
|
8
|
+
topic.has_many(:doors).run(Riot::Situation.new)
|
9
|
+
end.equals([:pass])
|
10
|
+
|
11
|
+
should("fail when record does not have a has_many association defined for attribute") do
|
12
|
+
topic.has_many(:windows).run(Riot::Situation.new)
|
13
|
+
end.equals([:fail, "expected :windows to be a has_many association, but was not"])
|
14
|
+
|
15
|
+
should("fail when attribute is not a has_many, but is a has_one association") do
|
16
|
+
topic.has_many(:floor).run(Riot::Situation.new)
|
17
|
+
end.equals([:fail, "expected :floor to be a has_many association, but was a has_one instead"])
|
18
|
+
end # The has_many assertion macro
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'teststrap'
|
2
2
|
|
3
|
-
context "validates_presence_of" do
|
4
|
-
|
5
|
-
|
6
|
-
test_ctx.topic.validates_presence_of(:location)
|
7
|
-
end
|
3
|
+
context "The validates_presence_of assertion macro" do
|
4
|
+
setup_test_context
|
5
|
+
setup { topic.asserts("room") { Room.new } }
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
should("pass when attribute requires presence") do
|
8
|
+
topic.validates_presence_of(:location).run(Riot::Situation.new)
|
9
|
+
end.equals([:pass])
|
10
|
+
|
11
|
+
should("fail when attribute does not require presence") do
|
12
|
+
topic.validates_presence_of(:contents).run(Riot::Situation.new)
|
13
|
+
end.equals([:fail, "expected to validate presence of :contents"])
|
14
|
+
end # The validates_presence_of assertion macro
|
@@ -1,20 +1,23 @@
|
|
1
1
|
require 'teststrap'
|
2
2
|
|
3
|
-
context "validates_uniqueness_of" do
|
3
|
+
context "The validates_uniqueness_of assertion macro" do
|
4
|
+
setup_test_context
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
should("fail without a persisted record") do
|
7
|
+
topic.asserts("room") do
|
8
|
+
Room.new(:email => "foo@bar.baz", :foo => "what")
|
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"])
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
should("pass with a persisted record") do
|
13
|
+
topic.asserts("room") do
|
14
|
+
Room.create_with_good_data(:email => "foo@bar.baz")
|
15
|
+
end.validates_uniqueness_of(:email).run(Riot::Situation.new)
|
16
|
+
end.equals([:pass])
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end # validates_uniqueness_of
|
18
|
+
should("fail with a persisted record but not validating uniqueness") do
|
19
|
+
topic.asserts("room") do
|
20
|
+
Room.new(:email => "goo@car.caz")
|
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"])
|
23
|
+
end # The validates_uniqueness_of assertion macro
|
data/test/teststrap.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'active_record'
|
3
5
|
require 'action_controller'
|
@@ -59,29 +61,74 @@ require 'riot/rails'
|
|
59
61
|
|
60
62
|
module RiotRails
|
61
63
|
module Context
|
62
|
-
def asserts_passes_failures_errors(passes=0, failures=0, errors=0)
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
# def asserts_passes_failures_errors(passes=0, failures=0, errors=0)
|
65
|
+
# should("pass #{passes} test(s)") { topic.passes }.equals(passes)
|
66
|
+
# should("fail #{failures} test(s)") { topic.failures }.equals(failures)
|
67
|
+
# should("error on #{errors} test(s)") { topic.errors }.equals(errors)
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# def setup_with_test_context(&block)
|
71
|
+
# setup do
|
72
|
+
# @test_report = Riot::SilentReporter.new
|
73
|
+
# @test_context = Riot::Context.new("test context", @test_report)
|
74
|
+
# yield(@test_context)
|
75
|
+
# @test_context.report
|
76
|
+
# @test_report
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# def setup_and_run_context(name, *passes_failures_errors, &block)
|
81
|
+
# context name do
|
82
|
+
# setup_with_test_context(&block)
|
83
|
+
# asserts_passes_failures_errors(*passes_failures_errors)
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
|
87
|
+
def setup_test_context
|
88
|
+
setup { Riot::Context.new("test context") {} }
|
66
89
|
end
|
67
90
|
|
68
|
-
def
|
91
|
+
def setup_for_assertion_test(&block)
|
69
92
|
setup do
|
70
|
-
@
|
71
|
-
|
72
|
-
yield(@test_context)
|
73
|
-
@test_context.report
|
74
|
-
@test_report
|
93
|
+
topic.setup(&block).last.run(@situation)
|
94
|
+
topic
|
75
95
|
end
|
76
96
|
end
|
97
|
+
|
98
|
+
def assertion_test_passes(description, &block)
|
99
|
+
should("pass #{description}") do
|
100
|
+
instance_eval(&block).run(@situation)
|
101
|
+
end.equals([:pass])
|
102
|
+
end
|
77
103
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
104
|
+
def assertion_test_fails(description, failure_message, &block)
|
105
|
+
should("fail #{description}") do
|
106
|
+
instance_eval(&block).run(@situation)
|
107
|
+
end.equals([:fail, failure_message])
|
83
108
|
end
|
84
|
-
|
85
|
-
end
|
109
|
+
|
110
|
+
end # Context
|
111
|
+
end # RiotRails
|
86
112
|
|
87
113
|
Riot::Context.instance_eval { include RiotRails::Context }
|
114
|
+
|
115
|
+
#
|
116
|
+
## Let's see if we can get this way working sometime in the future
|
117
|
+
|
118
|
+
# def get(action, options={})
|
119
|
+
# @env = {}
|
120
|
+
# @request = ActionController::TestRequest.new(@env)
|
121
|
+
# # @request = Rack::MockRequest.new(@app)
|
122
|
+
# # @response = @request.request("GET", path, options)
|
123
|
+
# # request = ActionController::TestRequest.new(@env)
|
124
|
+
# @request.query_parameters["action"] = action
|
125
|
+
# @env["action_controller.rescue.request"] = @request
|
126
|
+
# @env["action_controller.rescue.response"] = ActionController::TestResponse.new
|
127
|
+
# @app.call(@env)
|
128
|
+
# end
|
129
|
+
|
130
|
+
# setup do
|
131
|
+
# DashboardsController.instance_eval { include ActionController::TestCase::RaiseActionExceptions }
|
132
|
+
# @controller_class = DashboardsController
|
133
|
+
# @app = DashboardsController
|
134
|
+
# end
|
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.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin 'Gus' Knowlden
|
@@ -9,18 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-27 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: riot
|
17
|
-
type: :
|
17
|
+
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.10.2
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activerecord
|
@@ -55,7 +55,6 @@ files:
|
|
55
55
|
- lib/riot/rails.rb
|
56
56
|
- rails/init.rb
|
57
57
|
- riot_rails.gemspec
|
58
|
-
- test/action_controller/action_assigns_variable_test.rb
|
59
58
|
- test/action_controller/controller_context_test.rb
|
60
59
|
- test/action_controller/redirected_to_test.rb
|
61
60
|
- test/action_controller/renders_template_test.rb
|
@@ -98,7 +97,6 @@ signing_key:
|
|
98
97
|
specification_version: 3
|
99
98
|
summary: Riot specific test support for Rails apps
|
100
99
|
test_files:
|
101
|
-
- test/action_controller/action_assigns_variable_test.rb
|
102
100
|
- test/action_controller/controller_context_test.rb
|
103
101
|
- test/action_controller/redirected_to_test.rb
|
104
102
|
- test/action_controller/renders_template_test.rb
|
File without changes
|