riot_rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/VERSION +1 -1
- data/lib/riot/action_controller/assertion_macros.rb +94 -0
- data/lib/riot/action_controller/context_macros.rb +47 -0
- data/lib/riot/action_controller/situation_macros.rb +14 -0
- data/lib/riot/action_controller.rb +6 -0
- data/lib/riot/active_record/{macros.rb → context_macros.rb} +5 -15
- data/lib/riot/active_record/situation_macros.rb +16 -0
- data/lib/riot/active_record.rb +2 -0
- data/lib/riot/rails.rb +2 -1
- data/riot_rails.gemspec +35 -13
- data/test/action_controller/action_assigns_variable_test.rb +0 -0
- data/test/action_controller/controller_context_test.rb +67 -0
- data/test/action_controller/redirected_to_test.rb +60 -0
- data/test/action_controller/renders_template_test.rb +93 -0
- data/test/action_controller/renders_test.rb +56 -0
- data/test/action_controller/response_status_test.rb +88 -0
- data/test/{should_allow_values_for_test.rb → active_record/should_allow_values_for_test.rb} +1 -1
- data/test/{should_validate_presence_of_test.rb → active_record/should_validate_presence_of_test.rb} +1 -1
- data/test/{should_validate_uniqueness_of_test.rb → active_record/should_validate_uniqueness_of_test.rb} +1 -1
- data/test/rails_root/app/views/rendered_templates/foo_bar.erb +0 -0
- data/test/rails_root/config/routes.rb +5 -0
- data/test/{test_helper.rb → teststrap.rb} +17 -5
- metadata +33 -11
data/.gitignore
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Riot #:nodoc:
|
2
|
+
module ActionController #:nodoc:
|
3
|
+
|
4
|
+
module AssertionMacros
|
5
|
+
# Asserts that the body of the response equals or matches the expected expression. Expects actual to
|
6
|
+
# be the controller.
|
7
|
+
#
|
8
|
+
# controller.renders("a bunch of html")
|
9
|
+
# controller.renders(/bunch of/)
|
10
|
+
def renders(expected)
|
11
|
+
actual_body = actual.response.body
|
12
|
+
if expected.kind_of?(Regexp)
|
13
|
+
msg = "expected response body #{actual_body.inspect} to match #{expected.inspect}"
|
14
|
+
actual_body =~ expected || fail(msg)
|
15
|
+
else
|
16
|
+
msg = "expected response body #{actual_body.inspect} to equal #{expected.inspect}"
|
17
|
+
expected == actual_body || fail(msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Asserts that the name you provide is the basename of the rendered template. For instance, if you
|
22
|
+
# expect the rendered template is named "foo_bar.html.haml" and you pass "foo_bar" into
|
23
|
+
# renders_template, the assertion would pass. If instead you pass "foo" into renders_template, the
|
24
|
+
# assertion will fail. Using Rails' assert_template both assertions would pass
|
25
|
+
#
|
26
|
+
# controlling :things
|
27
|
+
# controller.renders_template(:index)
|
28
|
+
# controller.renders_template("index")
|
29
|
+
# controller.renders_template("index.erb") # fails even if that's the name of the template
|
30
|
+
def renders_template(name)
|
31
|
+
name = name.to_s
|
32
|
+
actual_template_path = actual.response.rendered[:template].to_s
|
33
|
+
actual_template_name = File.basename(actual_template_path)
|
34
|
+
msg = "expected template #{name.inspect}, not #{actual_template_path.inspect}"
|
35
|
+
actual_template_name.to_s.match(/^#{name}(\.\w+)?$/) || fail(msg)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Asserts that the HTTP response code equals your expectation. You can use the symbolized form of the
|
39
|
+
# status code or the integer code itself. Not currently supporting status ranges; such as: +:success+,
|
40
|
+
# +:redirect+, etc.
|
41
|
+
#
|
42
|
+
# controller.response_code(:ok)
|
43
|
+
# controller.response_code(200)
|
44
|
+
#
|
45
|
+
# controller.response_code(:not_found)
|
46
|
+
# controller.response_code(404)
|
47
|
+
#
|
48
|
+
# # A redirect
|
49
|
+
# controller.response_code(:found)
|
50
|
+
# controller.response_code(302)
|
51
|
+
#
|
52
|
+
# See +ActionController::StatusCodes+ for the list of available codes.
|
53
|
+
def response_code(expected_code)
|
54
|
+
if expected_code.kind_of?(Symbol)
|
55
|
+
expected_code = ::ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[expected_code]
|
56
|
+
end
|
57
|
+
actual_code = actual.response.response_code
|
58
|
+
expected_code == actual_code || fail("expected response code #{expected_code}, not #{actual_code}")
|
59
|
+
end
|
60
|
+
|
61
|
+
# Asserts that the response from an action is a redirect and that the path or URL matches your
|
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 }
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Riot #:nodoc:
|
2
|
+
module ActionController #:nodoc:
|
3
|
+
|
4
|
+
module ContextMacros
|
5
|
+
# Sets up a context (and possibly child contexts) for testing a controller. Right now, it just takes a
|
6
|
+
# symbol. Should change to allow you to pass in the class directly. You should put this at or near the
|
7
|
+
# top of your context definition.
|
8
|
+
#
|
9
|
+
# context "the FooBarsController" do
|
10
|
+
# controlling :foo_bars
|
11
|
+
# setup { get :index }
|
12
|
+
# end
|
13
|
+
def controlling(controller_name)
|
14
|
+
controller_class = "#{controller_name.to_s.camelize}Controller".constantize
|
15
|
+
setup do
|
16
|
+
controller_class.instance_eval { include ::ActionController::TestCase::RaiseActionExceptions }
|
17
|
+
@request = ::ActionController::TestRequest.new
|
18
|
+
@response = ::ActionController::TestResponse.new
|
19
|
+
@controller = controller_class.new
|
20
|
+
@controller.params = {}
|
21
|
+
@controller.request = @request
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Creates a shortcut assertion that is to be used with the assertion macros for ActionController.
|
26
|
+
#
|
27
|
+
# context "the FoosController" do
|
28
|
+
# controlling :foos
|
29
|
+
# setup { get :index }
|
30
|
+
#
|
31
|
+
# controller.response_status(:found)
|
32
|
+
# controller.redirected_to { new_foo_path }
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# Works the same as if you wrote the following assertions:
|
36
|
+
#
|
37
|
+
# asserts("controller") { @controller }.response_status(:found)
|
38
|
+
# asserts("controller") { @controller }.redirected_to { new_foo_path }
|
39
|
+
def controller
|
40
|
+
asserts("controller") { @controller }
|
41
|
+
end
|
42
|
+
end # ContextMacros
|
43
|
+
|
44
|
+
end # ActionController
|
45
|
+
end # Riot
|
46
|
+
|
47
|
+
Riot::Context.instance_eval { include Riot::ActionController::ContextMacros }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Riot #:nodoc:
|
2
|
+
module ActionController #:nodoc:
|
3
|
+
|
4
|
+
module SituationMacros
|
5
|
+
attr_reader :controller, :request, :response
|
6
|
+
end # SituationMacros
|
7
|
+
|
8
|
+
end # ActionController
|
9
|
+
end # Riot
|
10
|
+
|
11
|
+
Riot::Situation.instance_eval do
|
12
|
+
include ActionController::TestProcess
|
13
|
+
include Riot::ActionController::SituationMacros
|
14
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Riot
|
2
2
|
module ActiveRecord
|
3
|
-
|
3
|
+
|
4
|
+
module ContextMacros
|
4
5
|
# An ActiveRecord assertion that expects to fail when a given attribute or attributes are validated
|
5
6
|
# when a nil value is provided to them.
|
6
7
|
#
|
@@ -60,20 +61,9 @@ module Riot
|
|
60
61
|
get_error_from_writing_value(copied_model, attribute, copied_value)
|
61
62
|
end.exists
|
62
63
|
end
|
63
|
-
end #
|
64
|
-
end # ActiveRecord
|
64
|
+
end # ContextMacros
|
65
65
|
|
66
|
-
|
67
|
-
module Situation
|
68
|
-
private
|
69
|
-
def get_error_from_writing_value(model, attribute, value)
|
70
|
-
model.write_attribute(attribute, value)
|
71
|
-
model.valid?
|
72
|
-
model.errors.on(attribute)
|
73
|
-
end
|
74
|
-
end # Situation
|
75
|
-
end # Helpers
|
66
|
+
end # ActiveRecord
|
76
67
|
end # Riot
|
77
68
|
|
78
|
-
Riot::Context.instance_eval { include Riot::ActiveRecord::
|
79
|
-
Riot::Situation.instance_eval { include Riot::Helpers::Situation }
|
69
|
+
Riot::Context.instance_eval { include Riot::ActiveRecord::ContextMacros }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Riot
|
2
|
+
module ActiveRecord
|
3
|
+
|
4
|
+
module SituationMacros
|
5
|
+
private
|
6
|
+
def get_error_from_writing_value(model, attribute, value)
|
7
|
+
model.write_attribute(attribute, value)
|
8
|
+
model.valid?
|
9
|
+
model.errors.on(attribute)
|
10
|
+
end
|
11
|
+
end # SituationMacros
|
12
|
+
|
13
|
+
end # ActiveRecord
|
14
|
+
end # Riot
|
15
|
+
|
16
|
+
Riot::Situation.instance_eval { include Riot::ActiveRecord::SituationMacros }
|
data/lib/riot/rails.rb
CHANGED
data/riot_rails.gemspec
CHANGED
@@ -5,30 +5,45 @@
|
|
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.2"
|
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-10-
|
12
|
+
s.date = %q{2009-10-16}
|
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 = [
|
16
16
|
"README.markdown"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
"
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
20
21
|
"README.markdown",
|
21
22
|
"Rakefile",
|
22
23
|
"VERSION",
|
23
|
-
"lib/riot/
|
24
|
+
"lib/riot/action_controller.rb",
|
25
|
+
"lib/riot/action_controller/assertion_macros.rb",
|
26
|
+
"lib/riot/action_controller/context_macros.rb",
|
27
|
+
"lib/riot/action_controller/situation_macros.rb",
|
28
|
+
"lib/riot/active_record.rb",
|
29
|
+
"lib/riot/active_record/context_macros.rb",
|
30
|
+
"lib/riot/active_record/situation_macros.rb",
|
24
31
|
"lib/riot/rails.rb",
|
25
32
|
"rails/init.rb",
|
26
33
|
"riot_rails.gemspec",
|
34
|
+
"test/action_controller/action_assigns_variable_test.rb",
|
35
|
+
"test/action_controller/controller_context_test.rb",
|
36
|
+
"test/action_controller/redirected_to_test.rb",
|
37
|
+
"test/action_controller/renders_template_test.rb",
|
38
|
+
"test/action_controller/renders_test.rb",
|
39
|
+
"test/action_controller/response_status_test.rb",
|
40
|
+
"test/active_record/should_allow_values_for_test.rb",
|
41
|
+
"test/active_record/should_validate_presence_of_test.rb",
|
42
|
+
"test/active_record/should_validate_uniqueness_of_test.rb",
|
43
|
+
"test/rails_root/app/views/rendered_templates/foo_bar.erb",
|
44
|
+
"test/rails_root/config/routes.rb",
|
27
45
|
"test/rails_root/db/schema.rb",
|
28
|
-
"test/
|
29
|
-
"test/should_validate_presence_of_test.rb",
|
30
|
-
"test/should_validate_uniqueness_of_test.rb",
|
31
|
-
"test/test_helper.rb"
|
46
|
+
"test/teststrap.rb"
|
32
47
|
]
|
33
48
|
s.homepage = %q{http://github.com/thumblemonks/riot_rails}
|
34
49
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -36,11 +51,18 @@ Gem::Specification.new do |s|
|
|
36
51
|
s.rubygems_version = %q{1.3.5}
|
37
52
|
s.summary = %q{Riot specific test support for Rails apps}
|
38
53
|
s.test_files = [
|
39
|
-
"test/
|
40
|
-
"test/
|
41
|
-
"test/
|
42
|
-
"test/
|
43
|
-
"test/
|
54
|
+
"test/action_controller/action_assigns_variable_test.rb",
|
55
|
+
"test/action_controller/controller_context_test.rb",
|
56
|
+
"test/action_controller/redirected_to_test.rb",
|
57
|
+
"test/action_controller/renders_template_test.rb",
|
58
|
+
"test/action_controller/renders_test.rb",
|
59
|
+
"test/action_controller/response_status_test.rb",
|
60
|
+
"test/active_record/should_allow_values_for_test.rb",
|
61
|
+
"test/active_record/should_validate_presence_of_test.rb",
|
62
|
+
"test/active_record/should_validate_uniqueness_of_test.rb",
|
63
|
+
"test/rails_root/config/routes.rb",
|
64
|
+
"test/rails_root/db/schema.rb",
|
65
|
+
"test/teststrap.rb"
|
44
66
|
]
|
45
67
|
|
46
68
|
if s.respond_to? :specification_version then
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
class FoosController < ActionController::Base
|
4
|
+
end
|
5
|
+
|
6
|
+
context "controlling in a context" do
|
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
|
53
|
+
|
54
|
+
end # controlling in a context
|
55
|
+
|
56
|
+
context "a controller test" do
|
57
|
+
controlling :foos
|
58
|
+
|
59
|
+
asserts("situation") { self }.respond_to(:get)
|
60
|
+
asserts("situation") { self }.respond_to(:post)
|
61
|
+
asserts("situation") { self }.respond_to(:put)
|
62
|
+
asserts("situation") { self }.respond_to(:delete)
|
63
|
+
|
64
|
+
asserts "an unknown action" do
|
65
|
+
get :burberry
|
66
|
+
end.raises(ActionController::UnknownAction, "No action responded to burberry")
|
67
|
+
end # a controller
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
class RedirectedToController < ActionController::Base
|
4
|
+
def index; redirect_to new_gremlin_path; end
|
5
|
+
def show; render :text => ""; end
|
6
|
+
end
|
7
|
+
|
8
|
+
context "asserting the redirect of an action" do
|
9
|
+
|
10
|
+
setup do
|
11
|
+
context = Riot::Context.new("redirected to", Riot::NilReport.new)
|
12
|
+
context.controlling :redirected_to
|
13
|
+
context
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when doing an actual redirect" do
|
17
|
+
|
18
|
+
setup do
|
19
|
+
topic.setup { get :index }
|
20
|
+
topic
|
21
|
+
end
|
22
|
+
|
23
|
+
should "pass when expected url matches actual redirect url" do
|
24
|
+
assertion = topic.controller
|
25
|
+
assertion.redirected_to { new_gremlin_path }
|
26
|
+
assertion.passed?
|
27
|
+
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
|
+
end # when doing an actual redirect
|
44
|
+
|
45
|
+
context "when not actually doing a redirect" do
|
46
|
+
setup do
|
47
|
+
topic.setup { get :show }
|
48
|
+
assertion = topic.controller
|
49
|
+
assertion.redirected_to { new_gremlin_path }
|
50
|
+
assertion
|
51
|
+
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
|
+
end # when not actually doing a redirect
|
59
|
+
|
60
|
+
end # asserting the redirect of an action
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
class RenderedTemplatesController < ActionController::Base
|
4
|
+
def foo_bar; end
|
5
|
+
def text_me; render :text => "blah"; end
|
6
|
+
end
|
7
|
+
|
8
|
+
context "asserting the rendered template for an action" do
|
9
|
+
|
10
|
+
setup do
|
11
|
+
context = Riot::Context.new("rendered template", Riot::NilReport.new)
|
12
|
+
context.controlling :rendered_templates
|
13
|
+
context
|
14
|
+
end
|
15
|
+
|
16
|
+
context "that rendered a template" do
|
17
|
+
setup do
|
18
|
+
topic.setup { get :foo_bar }
|
19
|
+
topic
|
20
|
+
end
|
21
|
+
|
22
|
+
should "pass when rendered template name matches expectation" do
|
23
|
+
assertion = topic.controller
|
24
|
+
assertion.renders_template('foo_bar')
|
25
|
+
assertion.passed?
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when rendered template does not match expectation" do
|
29
|
+
setup do
|
30
|
+
assertion = topic.controller
|
31
|
+
assertion.renders_template('bar_foo')
|
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.erb"/)
|
40
|
+
end # when rendered template does not match expectation
|
41
|
+
|
42
|
+
end # that rendered a template
|
43
|
+
|
44
|
+
context "that did not render a template as expected" do
|
45
|
+
setup do
|
46
|
+
topic.setup { get :text_me }
|
47
|
+
topic
|
48
|
+
end
|
49
|
+
|
50
|
+
should "pass when providing nil as expectation" do
|
51
|
+
assertion = topic.controller
|
52
|
+
assertion.renders_template(nil)
|
53
|
+
assertion.passed?
|
54
|
+
end
|
55
|
+
|
56
|
+
should "pass when providing empty string as expectation" do
|
57
|
+
assertion = topic.controller
|
58
|
+
assertion.renders_template("")
|
59
|
+
assertion.passed?
|
60
|
+
end
|
61
|
+
end # that did not render a template as expected
|
62
|
+
|
63
|
+
context "that did not render a template but expected one" do
|
64
|
+
setup do
|
65
|
+
topic.setup { get :text_me }
|
66
|
+
assertion = topic.controller
|
67
|
+
assertion.renders_template('text_me')
|
68
|
+
assertion
|
69
|
+
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
|
+
end # that did not render a template but expected one
|
77
|
+
|
78
|
+
context "that rendered a template with a partial match on template name" do
|
79
|
+
setup do
|
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? }
|
87
|
+
|
88
|
+
asserts("topic message") do
|
89
|
+
topic.result.message
|
90
|
+
end.matches(/expected template "foo", not "rendered_templates\/foo_bar.erb"/)
|
91
|
+
end # that rendered a template with a partial match on template name
|
92
|
+
|
93
|
+
end # asserting the rendered template for an action
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
class RendersController < ActionController::Base
|
4
|
+
def index; render :text => "Yo mama"; end
|
5
|
+
end
|
6
|
+
|
7
|
+
context "asserting the body of a response" do
|
8
|
+
|
9
|
+
setup do
|
10
|
+
context = Riot::Context.new("renders", Riot::NilReport.new)
|
11
|
+
context.controlling :renders
|
12
|
+
context.setup { get :index }
|
13
|
+
context
|
14
|
+
end
|
15
|
+
|
16
|
+
should "assert rendered action body equals expected" do
|
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? }
|
30
|
+
|
31
|
+
asserts("topic message") do
|
32
|
+
topic.result.message
|
33
|
+
end.matches(/expected response body "Yo mama" to equal "Yo"/)
|
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?
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when rendered action body does not match expected" do
|
43
|
+
setup do
|
44
|
+
assertion = topic.controller
|
45
|
+
assertion.renders(/obama/)
|
46
|
+
assertion
|
47
|
+
end
|
48
|
+
|
49
|
+
asserts("topic failed") { topic.failed? }
|
50
|
+
|
51
|
+
asserts("topic message") do
|
52
|
+
topic.result.message
|
53
|
+
end.matches(/expected response body "Yo mama" to match \/obama\//)
|
54
|
+
end # when rendered action body does not match expected
|
55
|
+
|
56
|
+
end # asserting the body of a response
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
class ResponseCodesController < ActionController::Base
|
4
|
+
def ok_go; render :text => ""; end
|
5
|
+
def fffound; redirect_to "http://your.momshou.se"; end
|
6
|
+
def make_me; render :text => "", :status => 201; end
|
7
|
+
end
|
8
|
+
|
9
|
+
context "asserting the response status for an action" do
|
10
|
+
|
11
|
+
setup do
|
12
|
+
context = Riot::Context.new("response status", Riot::NilReport.new)
|
13
|
+
context.controlling :response_codes
|
14
|
+
context
|
15
|
+
end
|
16
|
+
|
17
|
+
context "returning OK" do
|
18
|
+
setup do
|
19
|
+
topic.setup { get :ok_go }
|
20
|
+
topic
|
21
|
+
end
|
22
|
+
|
23
|
+
should "pass when asked if :ok" do
|
24
|
+
assertion = topic.controller
|
25
|
+
assertion.response_code(:ok)
|
26
|
+
assertion.passed?
|
27
|
+
end
|
28
|
+
|
29
|
+
should "pass when asked if 200" do
|
30
|
+
assertion = topic.controller
|
31
|
+
assertion.response_code(200)
|
32
|
+
assertion.passed?
|
33
|
+
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
|
+
end # returning OK
|
49
|
+
|
50
|
+
context "that is redirecting" do
|
51
|
+
setup do
|
52
|
+
topic.setup { get :fffound }
|
53
|
+
topic
|
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
|
67
|
+
end # that is redirecting
|
68
|
+
|
69
|
+
context "that has explicit status" do
|
70
|
+
setup do
|
71
|
+
topic.setup { get :make_me }
|
72
|
+
topic
|
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
|
86
|
+
end # that has explicit status
|
87
|
+
|
88
|
+
end # asserting the status of a response
|
File without changes
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
|
5
|
-
RAILS_ROOT = File.dirname(__FILE__) + '/rails_root'
|
2
|
+
require 'active_record'
|
3
|
+
require 'action_controller'
|
6
4
|
|
7
5
|
def shhh(&block)
|
8
6
|
orig_out = $stdout
|
@@ -11,14 +9,24 @@ def shhh(&block)
|
|
11
9
|
$stdout = orig_out
|
12
10
|
end
|
13
11
|
|
14
|
-
#
|
12
|
+
#
|
13
|
+
# Setup faux Rails environment
|
14
|
+
|
15
|
+
RAILS_ROOT = File.join(File.dirname(__FILE__), 'rails_root')
|
16
|
+
|
17
|
+
require File.join(RAILS_ROOT, "config", "routes.rb")
|
18
|
+
|
15
19
|
shhh do
|
16
20
|
ActiveRecord::Base.configurations = {"test" => { "adapter" => "sqlite3", "database" => ":memory:"}}
|
17
21
|
ActiveRecord::Base.establish_connection("test")
|
18
22
|
load(File.join(RAILS_ROOT, "db", "schema.rb"))
|
19
23
|
end
|
20
24
|
|
25
|
+
ActionController::Base.view_paths = [File.join(RAILS_ROOT, 'app', 'views')]
|
26
|
+
|
27
|
+
#
|
21
28
|
# Model definition
|
29
|
+
|
22
30
|
class Room < ActiveRecord::Base
|
23
31
|
validates_presence_of :location, :foo, :bar
|
24
32
|
validates_format_of :email, :with => /^\w+@\w+\.\w+$/
|
@@ -29,7 +37,11 @@ class Room < ActiveRecord::Base
|
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
40
|
+
#
|
32
41
|
# Test refactorings
|
42
|
+
|
43
|
+
require 'riot/rails'
|
44
|
+
|
33
45
|
module RiotRails
|
34
46
|
module Context
|
35
47
|
def asserts_passes_failures_errors(passes=0, failures=0, errors=0)
|
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.2
|
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-10-
|
12
|
+
date: 2009-10-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -41,19 +41,34 @@ extensions: []
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- README.markdown
|
43
43
|
files:
|
44
|
+
- .gitignore
|
44
45
|
- MIT-LICENSE
|
45
46
|
- README.markdown
|
46
47
|
- Rakefile
|
47
48
|
- VERSION
|
48
|
-
- lib/riot/
|
49
|
+
- lib/riot/action_controller.rb
|
50
|
+
- lib/riot/action_controller/assertion_macros.rb
|
51
|
+
- lib/riot/action_controller/context_macros.rb
|
52
|
+
- lib/riot/action_controller/situation_macros.rb
|
53
|
+
- lib/riot/active_record.rb
|
54
|
+
- lib/riot/active_record/context_macros.rb
|
55
|
+
- lib/riot/active_record/situation_macros.rb
|
49
56
|
- lib/riot/rails.rb
|
50
57
|
- rails/init.rb
|
51
58
|
- riot_rails.gemspec
|
59
|
+
- test/action_controller/action_assigns_variable_test.rb
|
60
|
+
- test/action_controller/controller_context_test.rb
|
61
|
+
- test/action_controller/redirected_to_test.rb
|
62
|
+
- test/action_controller/renders_template_test.rb
|
63
|
+
- test/action_controller/renders_test.rb
|
64
|
+
- test/action_controller/response_status_test.rb
|
65
|
+
- test/active_record/should_allow_values_for_test.rb
|
66
|
+
- test/active_record/should_validate_presence_of_test.rb
|
67
|
+
- test/active_record/should_validate_uniqueness_of_test.rb
|
68
|
+
- test/rails_root/app/views/rendered_templates/foo_bar.erb
|
69
|
+
- test/rails_root/config/routes.rb
|
52
70
|
- test/rails_root/db/schema.rb
|
53
|
-
- test/
|
54
|
-
- test/should_validate_presence_of_test.rb
|
55
|
-
- test/should_validate_uniqueness_of_test.rb
|
56
|
-
- test/test_helper.rb
|
71
|
+
- test/teststrap.rb
|
57
72
|
has_rdoc: true
|
58
73
|
homepage: http://github.com/thumblemonks/riot_rails
|
59
74
|
licenses: []
|
@@ -83,8 +98,15 @@ signing_key:
|
|
83
98
|
specification_version: 3
|
84
99
|
summary: Riot specific test support for Rails apps
|
85
100
|
test_files:
|
101
|
+
- test/action_controller/action_assigns_variable_test.rb
|
102
|
+
- test/action_controller/controller_context_test.rb
|
103
|
+
- test/action_controller/redirected_to_test.rb
|
104
|
+
- test/action_controller/renders_template_test.rb
|
105
|
+
- test/action_controller/renders_test.rb
|
106
|
+
- test/action_controller/response_status_test.rb
|
107
|
+
- test/active_record/should_allow_values_for_test.rb
|
108
|
+
- test/active_record/should_validate_presence_of_test.rb
|
109
|
+
- test/active_record/should_validate_uniqueness_of_test.rb
|
110
|
+
- test/rails_root/config/routes.rb
|
86
111
|
- test/rails_root/db/schema.rb
|
87
|
-
- test/
|
88
|
-
- test/should_validate_presence_of_test.rb
|
89
|
-
- test/should_validate_uniqueness_of_test.rb
|
90
|
-
- test/test_helper.rb
|
112
|
+
- test/teststrap.rb
|