rspec-rails 2.99.0 → 3.0.0.beta1
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.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +40 -68
- data/License.txt +1 -0
- data/README.md +6 -4
- data/features/Generators.md +24 -0
- data/features/GettingStarted.md +84 -0
- data/features/README.md +56 -0
- data/features/RailsVersions.md +4 -0
- data/features/Transactions.md +84 -0
- data/features/Upgrade.md +121 -0
- data/features/controller_specs/Cookies.md +57 -0
- data/features/controller_specs/README.md +45 -0
- data/features/controller_specs/anonymous_controller.feature +378 -0
- data/features/controller_specs/bypass_rescue.feature +75 -0
- data/features/controller_specs/controller_spec.feature +58 -0
- data/features/controller_specs/engine_routes.feature +51 -0
- data/features/controller_specs/isolation_from_views.feature +87 -0
- data/features/controller_specs/render_views.feature +114 -0
- data/features/directory_structure.feature +71 -0
- data/features/feature_specs/feature_spec.feature +35 -0
- data/features/helper_specs/helper_spec.feature +122 -0
- data/features/mailer_specs/url_helpers.feature +38 -0
- data/features/matchers/README.md +18 -0
- data/features/matchers/new_record_matcher.feature +41 -0
- data/features/matchers/redirect_to_matcher.feature +40 -0
- data/features/matchers/relation_match_array.feature +27 -0
- data/features/matchers/render_template_matcher.feature +49 -0
- data/features/mocks/mock_model.feature +147 -0
- data/features/mocks/stub_model.feature +58 -0
- data/features/model_specs/README.md +21 -0
- data/features/model_specs/errors_on.feature +51 -0
- data/features/model_specs/records.feature +27 -0
- data/features/model_specs/transactional_examples.feature +109 -0
- data/features/request_specs/request_spec.feature +49 -0
- data/features/routing_specs/README.md +16 -0
- data/features/routing_specs/be_routable_matcher.feature +80 -0
- data/features/routing_specs/engine_routes.feature +38 -0
- data/features/routing_specs/named_routes.feature +18 -0
- data/features/routing_specs/route_to_matcher.feature +90 -0
- data/features/step_definitions/additional_cli_steps.rb +4 -0
- data/features/step_definitions/model_steps.rb +3 -0
- data/features/support/capybara.rb +7 -0
- data/features/support/env.rb +53 -0
- data/features/support/rails_versions.rb +4 -0
- data/features/support/rubinius.rb +6 -0
- data/features/view_specs/inferred_controller_path.feature +45 -0
- data/features/view_specs/stub_template.feature +51 -0
- data/features/view_specs/view_spec.feature +206 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +2 -21
- data/lib/generators/rspec/integration/integration_generator.rb +2 -3
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +4 -4
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +2 -3
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +16 -16
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +7 -7
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/rspec/rails.rb +0 -5
- data/lib/rspec/rails/adapters.rb +5 -12
- data/lib/rspec/rails/example.rb +55 -24
- data/lib/rspec/rails/example/controller_example_group.rb +7 -31
- data/lib/rspec/rails/example/view_example_group.rb +0 -3
- data/lib/rspec/rails/matchers.rb +1 -2
- data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
- data/lib/rspec/rails/matchers/be_valid.rb +1 -1
- data/lib/rspec/rails/matchers/have_rendered.rb +1 -1
- data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +6 -10
- data/lib/rspec/rails/mocks.rb +5 -41
- data/lib/rspec/rails/tasks/rspec.rake +5 -12
- data/lib/rspec/rails/vendor/capybara.rb +4 -35
- data/lib/rspec/rails/version.rb +1 -1
- data/spec/generators/rspec/controller/controller_generator_spec.rb +97 -0
- data/spec/generators/rspec/helper/helper_generator_spec.rb +30 -0
- data/spec/generators/rspec/install/install_generator_spec.rb +30 -0
- data/spec/generators/rspec/integration/integration_generator_spec.rb +44 -0
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +48 -0
- data/spec/generators/rspec/model/model_generator_spec.rb +52 -0
- data/spec/generators/rspec/observer/observer_generator_spec.rb +21 -0
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +138 -0
- data/spec/generators/rspec/view/view_generator_spec.rb +41 -0
- data/spec/rspec/rails/assertion_adapter_spec.rb +28 -0
- data/spec/rspec/rails/assertion_delegator_spec.rb +43 -0
- data/spec/rspec/rails/configuration_spec.rb +26 -0
- data/spec/rspec/rails/deprecations_spec.rb +18 -0
- data/spec/rspec/rails/example/controller_example_group_spec.rb +100 -0
- data/spec/rspec/rails/example/feature_example_group_spec.rb +56 -0
- data/spec/rspec/rails/example/helper_example_group_spec.rb +66 -0
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +21 -0
- data/spec/rspec/rails/example/model_example_group_spec.rb +15 -0
- data/spec/rspec/rails/example/request_example_group_spec.rb +17 -0
- data/spec/rspec/rails/example/routing_example_group_spec.rb +32 -0
- data/spec/rspec/rails/example/view_example_group_spec.rb +220 -0
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
- data/spec/rspec/rails/extensions/active_record/base_spec.rb +42 -0
- data/spec/rspec/rails/fixture_support_spec.rb +17 -0
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +142 -0
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +33 -0
- data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
- data/spec/rspec/rails/matchers/be_valid_spec.rb +44 -0
- data/spec/rspec/rails/matchers/has_spec.rb +29 -0
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +93 -0
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +80 -0
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +31 -0
- data/spec/rspec/rails/matchers/route_to_spec.rb +151 -0
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +22 -0
- data/spec/rspec/rails/mocks/mock_model_spec.rb +378 -0
- data/spec/rspec/rails/mocks/stub_model_spec.rb +154 -0
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +32 -0
- data/spec/rspec/rails/view_rendering_spec.rb +111 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/ar_classes.rb +42 -0
- data/spec/support/helpers.rb +20 -0
- data/spec/support/matchers.rb +9 -0
- data/spec/support/null_object.rb +6 -0
- metadata +229 -42
- metadata.gz.sig +0 -0
- data/lib/autotest/rails_rspec2.rb +0 -91
- data/lib/rspec/rails/infer_type_configuration.rb +0 -26
- data/lib/rspec/rails/matchers/have_extension.rb +0 -36
- data/lib/rspec/rails/module_inclusion.rb +0 -19
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "errors_on" do
|
4
|
+
let(:klass) do
|
5
|
+
Class.new do
|
6
|
+
include ActiveModel::Validations
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "calls valid?" do
|
11
|
+
model = klass.new
|
12
|
+
model.should_receive(:valid?)
|
13
|
+
model.errors_on(:foo)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the errors on that attribute" do
|
17
|
+
model = klass.new
|
18
|
+
model.stub(:errors) do
|
19
|
+
{ :foo => ['a', 'b'] }
|
20
|
+
end
|
21
|
+
model.errors_on(:foo).should eq(['a','b'])
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::ActiveModel::Validations do
|
4
|
+
describe "#errors_on" do
|
5
|
+
context "ActiveModel class that takes no arguments to valid?" do
|
6
|
+
let(:klass) {
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
|
10
|
+
def self.name
|
11
|
+
"ActiveModelValidationsFake"
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_accessor :name
|
19
|
+
validates_presence_of :name
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
context "with nil name" do
|
24
|
+
it "has one error" do
|
25
|
+
object = klass.new
|
26
|
+
object.name = ""
|
27
|
+
|
28
|
+
expect(object).to have(1).error_on(:name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with non-blank name" do
|
33
|
+
it "has no error" do
|
34
|
+
object = klass.new
|
35
|
+
object.name = "Ywen"
|
36
|
+
|
37
|
+
expect(object).to have(:no).error_on(:name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module RSpec::Rails
|
4
|
+
describe FixtureSupport do
|
5
|
+
context "with use_transactional_fixtures set to false" do
|
6
|
+
it "still supports fixture_path" do
|
7
|
+
RSpec.configuration.stub(:use_transactional_fixtures) { false }
|
8
|
+
group = RSpec::Core::ExampleGroup.describe do
|
9
|
+
include FixtureSupport
|
10
|
+
end
|
11
|
+
|
12
|
+
group.should respond_to(:fixture_path)
|
13
|
+
group.should respond_to(:fixture_path=)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "be_a_new matcher" do
|
4
|
+
include RSpec::Rails::Matchers
|
5
|
+
|
6
|
+
context "new record" do
|
7
|
+
let(:record) do
|
8
|
+
Class.new do
|
9
|
+
def new_record?; true; end
|
10
|
+
end.new
|
11
|
+
end
|
12
|
+
context "right class" do
|
13
|
+
it "passes" do
|
14
|
+
record.should be_a_new(record.class)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
context "wrong class" do
|
18
|
+
it "fails" do
|
19
|
+
record.should_not be_a_new(String)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "existing record" do
|
25
|
+
let(:record) do
|
26
|
+
Class.new do
|
27
|
+
def new_record?; false; end
|
28
|
+
end.new
|
29
|
+
end
|
30
|
+
context "right class" do
|
31
|
+
it "fails" do
|
32
|
+
record.should_not be_a_new(record.class)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context "wrong class" do
|
36
|
+
it "fails" do
|
37
|
+
record.should_not be_a_new(String)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#with" do
|
43
|
+
context "right class and new record" do
|
44
|
+
let(:record) do
|
45
|
+
Class.new do
|
46
|
+
def initialize(attributes)
|
47
|
+
@attributes = attributes
|
48
|
+
end
|
49
|
+
|
50
|
+
def attributes
|
51
|
+
@attributes.stringify_keys
|
52
|
+
end
|
53
|
+
|
54
|
+
def new_record?; true; end
|
55
|
+
end.new(:foo => 'foo', :bar => 'bar')
|
56
|
+
end
|
57
|
+
|
58
|
+
context "all attributes same" do
|
59
|
+
it "passes" do
|
60
|
+
record.should be_a_new(record.class).with(:foo => 'foo', :bar => 'bar')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "one attribute same" do
|
65
|
+
it "passes" do
|
66
|
+
record.should be_a_new(record.class).with(:foo => 'foo')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "no attributes same" do
|
71
|
+
it "fails" do
|
72
|
+
expect {
|
73
|
+
record.should be_a_new(record.class).with(:zoo => 'zoo', :car => 'car')
|
74
|
+
}.to raise_error {|e|
|
75
|
+
e.message.should match(/attributes {.*} were not set on #{record.inspect}/)
|
76
|
+
e.message.should match(/"zoo"=>"zoo"/)
|
77
|
+
e.message.should match(/"car"=>"car"/)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "one attribute value not the same" do
|
83
|
+
it "fails" do
|
84
|
+
expect {
|
85
|
+
record.should be_a_new(record.class).with(:foo => 'bar')
|
86
|
+
}.to raise_error(
|
87
|
+
%Q(attribute {"foo"=>"bar"} was not set on #{record.inspect})
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "wrong class and existing record" do
|
94
|
+
let(:record) do
|
95
|
+
Class.new do
|
96
|
+
def initialize(attributes)
|
97
|
+
@attributes = attributes
|
98
|
+
end
|
99
|
+
|
100
|
+
def attributes
|
101
|
+
@attributes.stringify_keys
|
102
|
+
end
|
103
|
+
|
104
|
+
def new_record?; false; end
|
105
|
+
end.new(:foo => 'foo', :bar => 'bar')
|
106
|
+
end
|
107
|
+
|
108
|
+
context "all attributes same" do
|
109
|
+
it "fails" do
|
110
|
+
expect {
|
111
|
+
record.should be_a_new(String).with(:foo => 'foo', :bar => 'bar')
|
112
|
+
}.to raise_error(
|
113
|
+
"expected #{record.inspect} to be a new String"
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "no attributes same" do
|
119
|
+
it "fails" do
|
120
|
+
expect {
|
121
|
+
record.should be_a_new(String).with(:zoo => 'zoo', :car => 'car')
|
122
|
+
}.to raise_error {|e|
|
123
|
+
e.message.should match(/expected #{record.inspect} to be a new String and attributes {.*} were not set on #{record.inspect}/)
|
124
|
+
e.message.should match(/"zoo"=>"zoo"/)
|
125
|
+
e.message.should match(/"car"=>"car"/)
|
126
|
+
}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "one attribute value not the same" do
|
131
|
+
it "fails" do
|
132
|
+
expect {
|
133
|
+
record.should be_a_new(String).with(:foo => 'bar')
|
134
|
+
}.to raise_error(
|
135
|
+
"expected #{record.inspect} to be a new String and " +
|
136
|
+
%Q(attribute {"foo"=>"bar"} was not set on #{record.inspect})
|
137
|
+
)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "be_new_record" do
|
4
|
+
include RSpec::Rails::Matchers
|
5
|
+
|
6
|
+
context "un-persisted record" do
|
7
|
+
let(:record) { double('record', :persisted? => false) }
|
8
|
+
|
9
|
+
it "passes" do
|
10
|
+
record.should be_new_record
|
11
|
+
end
|
12
|
+
|
13
|
+
it "fails with custom failure message" do
|
14
|
+
expect {
|
15
|
+
expect(record).not_to be_new_record
|
16
|
+
}.to raise_exception(/expected .* to be persisted, but was a new record/)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "persisted record" do
|
21
|
+
let(:record) { double('record', :persisted? => true) }
|
22
|
+
|
23
|
+
it "fails" do
|
24
|
+
record.should_not be_new_record
|
25
|
+
end
|
26
|
+
|
27
|
+
it "fails with custom failure message" do
|
28
|
+
expect {
|
29
|
+
expect(record).to be_new_record
|
30
|
+
}.to raise_exception(/expected .* to be a new record, but was persisted/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "be_routable" do
|
4
|
+
include RSpec::Rails::Matchers::RoutingMatchers
|
5
|
+
attr_reader :routes
|
6
|
+
|
7
|
+
before { @routes = double("routes") }
|
8
|
+
|
9
|
+
context "with should" do
|
10
|
+
it "passes if routes recognize the path" do
|
11
|
+
routes.stub(:recognize_path) { {} }
|
12
|
+
expect do
|
13
|
+
{:get => "/a/path"}.should be_routable
|
14
|
+
end.to_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "fails if routes do not recognize the path" do
|
18
|
+
routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
|
19
|
+
expect do
|
20
|
+
{:get => "/a/path"}.should be_routable
|
21
|
+
end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with should_not" do
|
26
|
+
|
27
|
+
it "passes if routes do not recognize the path" do
|
28
|
+
routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
|
29
|
+
expect do
|
30
|
+
{:get => "/a/path"}.should_not be_routable
|
31
|
+
end.to_not raise_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it "fails if routes recognize the path" do
|
35
|
+
routes.stub(:recognize_path) { {:controller => "foo"} }
|
36
|
+
expect do
|
37
|
+
{:get => "/a/path"}.should_not be_routable
|
38
|
+
end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'rspec/rails/matchers/be_valid'
|
4
|
+
|
5
|
+
describe "be_valid matcher" do
|
6
|
+
include RSpec::Rails::Matchers
|
7
|
+
|
8
|
+
class Post
|
9
|
+
include ActiveModel::Validations
|
10
|
+
attr_accessor :title
|
11
|
+
validates_presence_of :title
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:post) { Post.new }
|
15
|
+
|
16
|
+
it "includes the error messages in the failure message" do
|
17
|
+
expect {
|
18
|
+
expect(post).to be_valid
|
19
|
+
}.to raise_exception(/Title can't be blank/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "includes a failure message for the negative case" do
|
23
|
+
post.stub(:valid?) { true }
|
24
|
+
expect {
|
25
|
+
expect(post).not_to be_valid
|
26
|
+
}.to raise_exception(/expected .* not to be valid/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "uses a custom failure message if provided" do
|
30
|
+
expect {
|
31
|
+
expect(post).to be_valid, "Post was not valid!"
|
32
|
+
}.to raise_exception(/Post was not valid!/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "includes the validation context if provided" do
|
36
|
+
post.should_receive(:valid?).with(:create) { true }
|
37
|
+
expect(post).to be_valid(:create)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "does not include the validation context if not provided" do
|
41
|
+
post.should_receive(:valid?).with(no_args) { true }
|
42
|
+
expect(post).to be_valid
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CollectionOwner < ActiveRecord::Base
|
4
|
+
connection.execute <<-SQL
|
5
|
+
CREATE TABLE collection_owners (
|
6
|
+
id integer PRIMARY KEY AUTOINCREMENT
|
7
|
+
)
|
8
|
+
SQL
|
9
|
+
has_many :associated_items do
|
10
|
+
def has_some_quality?; true end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class AssociatedItem < ActiveRecord::Base
|
15
|
+
connection.execute <<-SQL
|
16
|
+
CREATE TABLE associated_items (
|
17
|
+
id integer PRIMARY KEY AUTOINCREMENT,
|
18
|
+
collection_owner_id integer
|
19
|
+
)
|
20
|
+
SQL
|
21
|
+
belongs_to :collection_owner
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "should have_xxx" do
|
25
|
+
it "works with ActiveRecord::Associations::CollectionProxy" do
|
26
|
+
owner = CollectionOwner.new
|
27
|
+
owner.associated_items.should have_some_quality
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
%w[have_rendered render_template].each do |template_expectation|
|
4
|
+
describe template_expectation do
|
5
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
6
|
+
let(:response) { ActionController::TestResponse.new }
|
7
|
+
|
8
|
+
context "given a hash" do
|
9
|
+
it "delegates to assert_template" do
|
10
|
+
self.should_receive(:assert_template).with({:this => "hash"}, "this message")
|
11
|
+
expect("response").to send(template_expectation, {:this => "hash"}, "this message")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "given a string" do
|
16
|
+
it "delegates to assert_template" do
|
17
|
+
self.should_receive(:assert_template).with("this string", "this message")
|
18
|
+
expect("response").to send(template_expectation, "this string", "this message")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "given a symbol" do
|
23
|
+
it "converts to_s and delegates to assert_template" do
|
24
|
+
self.should_receive(:assert_template).with("template_name", "this message")
|
25
|
+
expect("response").to send(template_expectation, :template_name, "this message")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with should" do
|
30
|
+
context "when assert_template passes" do
|
31
|
+
it "passes" do
|
32
|
+
def assert_template(*); end
|
33
|
+
expect do
|
34
|
+
expect(response).to send(template_expectation, "template_name")
|
35
|
+
end.to_not raise_exception
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when assert_template fails" do
|
40
|
+
it "uses failure message from assert_template" do
|
41
|
+
def assert_template(*)
|
42
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
43
|
+
end
|
44
|
+
expect do
|
45
|
+
expect(response).to send(template_expectation, "template_name")
|
46
|
+
end.to raise_error("this message")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when fails due to some other exception" do
|
51
|
+
it "raises that exception" do
|
52
|
+
def assert_template(*)
|
53
|
+
raise "oops"
|
54
|
+
end
|
55
|
+
expect do
|
56
|
+
expect(response).to send(template_expectation, "template_name")
|
57
|
+
end.to raise_exception("oops")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "with should_not" do
|
63
|
+
context "when assert_template fails" do
|
64
|
+
it "passes" do
|
65
|
+
def assert_template(*)
|
66
|
+
raise ActiveSupport::TestCase::Assertion.new("this message")
|
67
|
+
end
|
68
|
+
expect do
|
69
|
+
expect(response).to_not send(template_expectation, "template_name")
|
70
|
+
end.to_not raise_exception
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when assert_template passes" do
|
75
|
+
it "fails with custom failure message" do
|
76
|
+
def assert_template(*); end
|
77
|
+
expect do
|
78
|
+
expect(response).to_not send(template_expectation, "template_name")
|
79
|
+
end.to raise_error(/expected not to render \"template_name\", but did/)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when fails due to some other exception" do
|
84
|
+
it "raises that exception" do
|
85
|
+
def assert_template(*); raise "oops"; end
|
86
|
+
expect do
|
87
|
+
expect(response).to_not send(template_expectation, "template_name")
|
88
|
+
end.to raise_exception("oops")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|