rspec-rails 3.0.0.beta1 → 3.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/Changelog.md +46 -0
- data/README.md +19 -17
- data/features/Generators.md +1 -0
- data/features/README.md +7 -15
- data/features/controller_specs/anonymous_controller.feature +222 -164
- data/lib/generators/rspec/feature/feature_generator.rb +15 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +0 -6
- data/lib/generators/rspec/integration/integration_generator.rb +0 -11
- data/lib/generators/rspec/integration/templates/request_spec.rb +0 -5
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +0 -8
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +4 -4
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +0 -9
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +0 -7
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +0 -9
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +0 -7
- data/lib/rspec/rails.rb +1 -1
- data/lib/rspec/rails/adapters.rb +18 -15
- data/lib/rspec/rails/example/controller_example_group.rb +18 -9
- data/lib/rspec/rails/example/view_example_group.rb +3 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +2 -2
- data/lib/rspec/rails/matchers/be_valid.rb +10 -3
- data/lib/rspec/rails/matchers/have_rendered.rb +2 -2
- data/lib/rspec/rails/matchers/redirect_to.rb +2 -2
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +7 -3
- data/lib/rspec/rails/mocks.rb +50 -26
- data/lib/rspec/rails/vendor/capybara.rb +4 -4
- data/lib/rspec/rails/version.rb +1 -1
- data/spec/generators/rspec/controller/controller_generator_spec.rb +16 -16
- data/spec/generators/rspec/feature/feature_generator_spec.rb +43 -0
- data/spec/generators/rspec/helper/helper_generator_spec.rb +4 -4
- data/spec/generators/rspec/install/install_generator_spec.rb +4 -4
- data/spec/generators/rspec/integration/integration_generator_spec.rb +8 -20
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +11 -11
- data/spec/generators/rspec/model/model_generator_spec.rb +7 -7
- data/spec/generators/rspec/observer/observer_generator_spec.rb +3 -3
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +34 -34
- data/spec/generators/rspec/view/view_generator_spec.rb +6 -6
- data/spec/rspec/rails/assertion_adapter_spec.rb +3 -3
- data/spec/rspec/rails/configuration_spec.rb +2 -2
- data/spec/rspec/rails/deprecations_spec.rb +1 -1
- data/spec/rspec/rails/example/controller_example_group_spec.rb +79 -20
- data/spec/rspec/rails/example/feature_example_group_spec.rb +2 -2
- data/spec/rspec/rails/example/helper_example_group_spec.rb +12 -12
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +3 -3
- data/spec/rspec/rails/example/model_example_group_spec.rb +3 -3
- data/spec/rspec/rails/example/request_example_group_spec.rb +5 -5
- data/spec/rspec/rails/example/routing_example_group_spec.rb +5 -5
- data/spec/rspec/rails/example/view_example_group_spec.rb +44 -29
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +3 -3
- data/spec/rspec/rails/fixture_support_spec.rb +3 -3
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +17 -17
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +2 -2
- data/spec/rspec/rails/matchers/be_routable_spec.rb +8 -8
- data/spec/rspec/rails/matchers/be_valid_spec.rb +33 -4
- data/spec/rspec/rails/matchers/has_spec.rb +1 -1
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +3 -3
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +7 -6
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +6 -6
- data/spec/rspec/rails/matchers/route_to_spec.rb +21 -21
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +9 -0
- data/spec/rspec/rails/mocks/mock_model_spec.rb +95 -73
- data/spec/rspec/rails/mocks/stub_model_spec.rb +23 -23
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +4 -4
- data/spec/rspec/rails/view_rendering_spec.rb +14 -14
- data/spec/spec_helper.rb +3 -5
- data/spec/support/helpers.rb +15 -1
- metadata +112 -46
- metadata.gz.sig +0 -0
- checksums.yaml +0 -15
- checksums.yaml.gz.sig +0 -2
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class FeatureGenerator < Base
|
6
|
+
class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs"
|
7
|
+
|
8
|
+
def generate_feature_spec
|
9
|
+
return unless options[:feature_specs]
|
10
|
+
|
11
|
+
template 'feature_spec.rb', File.join('spec/features', class_path, "#{table_name}_spec.rb") # file_name?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
ENV["RAILS_ENV"] ||= 'test'
|
3
3
|
require File.expand_path("../../config/environment", __FILE__)
|
4
4
|
require 'rspec/rails'
|
5
|
-
require 'rspec/autorun'
|
6
5
|
|
7
6
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
8
7
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
@@ -36,11 +35,6 @@ RSpec.configure do |config|
|
|
36
35
|
# instead of true.
|
37
36
|
config.use_transactional_fixtures = true
|
38
37
|
|
39
|
-
# If true, the base class of anonymous controllers will be inferred
|
40
|
-
# automatically. This will be the default behavior in future versions of
|
41
|
-
# rspec-rails.
|
42
|
-
config.infer_base_class_for_anonymous_controllers = false
|
43
|
-
|
44
38
|
# Run specs in random order to surface order dependencies. If you find an
|
45
39
|
# order dependency and want to debug it, you can fix the order by providing
|
46
40
|
# the seed, which is printed after each run.
|
@@ -4,8 +4,6 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
class IntegrationGenerator < Base
|
6
6
|
class_option :request_specs, :type => :boolean, :default => true, :desc => "Generate request specs"
|
7
|
-
class_option :webrat, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
|
8
|
-
class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
|
9
7
|
|
10
8
|
def generate_request_spec
|
11
9
|
return unless options[:request_specs]
|
@@ -13,15 +11,6 @@ module Rspec
|
|
13
11
|
template 'request_spec.rb',
|
14
12
|
File.join('spec/requests', class_path, "#{table_name}_spec.rb")
|
15
13
|
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
# @deprecated Use `--webrat` instead.
|
20
|
-
def webrat?
|
21
|
-
RSpec.deprecate("the --webrat-matchers option", :replacement => "--webrat") if options[:webrat_matchers]
|
22
|
-
options[:webrat] || options[:webrat_matchers]
|
23
|
-
end
|
24
|
-
|
25
14
|
end
|
26
15
|
end
|
27
16
|
end
|
@@ -3,12 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe "<%= class_name.pluralize %>" do
|
4
4
|
describe "GET /<%= table_name %>" do
|
5
5
|
it "works! (now write some real specs)" do
|
6
|
-
<% if webrat? -%>
|
7
|
-
visit <%= index_helper %>_path
|
8
|
-
<% else -%>
|
9
|
-
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
10
6
|
get <%= index_helper %>_path
|
11
|
-
<% end -%>
|
12
7
|
expect(response.status).to be(200)
|
13
8
|
end
|
14
9
|
end
|
@@ -14,8 +14,6 @@ module Rspec
|
|
14
14
|
|
15
15
|
class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
|
16
16
|
class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
|
17
|
-
class_option :webrat, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
|
18
|
-
class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
|
19
17
|
class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs"
|
20
18
|
class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
|
21
19
|
|
@@ -46,12 +44,6 @@ module Rspec
|
|
46
44
|
|
47
45
|
protected
|
48
46
|
|
49
|
-
# @deprecated Use `--webrat` instead.
|
50
|
-
def webrat?
|
51
|
-
RSpec.deprecate("--webrat-matchers", :replacement => "--webrat") if options[:webrat_matchers]
|
52
|
-
options[:webrat] || options[:webrat_matchers]
|
53
|
-
end
|
54
|
-
|
55
47
|
def copy_view(view)
|
56
48
|
template "#{view}_spec.rb",
|
57
49
|
File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
@@ -87,14 +87,14 @@ describe <%= controller_class_name %>Controller do
|
|
87
87
|
describe "with invalid params" do
|
88
88
|
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
89
89
|
# Trigger the behavior that occurs when invalid params are submitted
|
90
|
-
<%= class_name
|
90
|
+
allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
|
91
91
|
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
92
92
|
expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "re-renders the 'new' template" do
|
96
96
|
# Trigger the behavior that occurs when invalid params are submitted
|
97
|
-
<%= class_name
|
97
|
+
allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
|
98
98
|
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
99
99
|
expect(response).to render_template("new")
|
100
100
|
end
|
@@ -134,7 +134,7 @@ describe <%= controller_class_name %>Controller do
|
|
134
134
|
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
135
135
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
136
|
# Trigger the behavior that occurs when invalid params are submitted
|
137
|
-
<%= class_name
|
137
|
+
allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
|
138
138
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
139
139
|
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
|
140
140
|
end
|
@@ -142,7 +142,7 @@ describe <%= controller_class_name %>Controller do
|
|
142
142
|
it "re-renders the 'edit' template" do
|
143
143
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
144
144
|
# Trigger the behavior that occurs when invalid params are submitted
|
145
|
-
<%= class_name
|
145
|
+
allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
|
146
146
|
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
147
147
|
expect(response).to render_template("edit")
|
148
148
|
end
|
@@ -13,19 +13,10 @@ describe "<%= ns_table_name %>/edit" do
|
|
13
13
|
it "renders the edit <%= ns_file_name %> form" do
|
14
14
|
render
|
15
15
|
|
16
|
-
<% if webrat? -%>
|
17
|
-
expect(rendered).to have_selector("form", :action => <%= ns_file_name %>_path(@<%= ns_file_name %>), :method => "post") do |form|
|
18
|
-
<% for attribute in output_attributes -%>
|
19
|
-
expect(form).to have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
20
|
-
<% end -%>
|
21
|
-
end
|
22
|
-
<% else -%>
|
23
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
24
16
|
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
|
25
17
|
<% for attribute in output_attributes -%>
|
26
18
|
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>[name=?]", "<%= ns_file_name %>[<%= attribute.name %>]"
|
27
19
|
<% end -%>
|
28
20
|
end
|
29
|
-
<% end -%>
|
30
21
|
end
|
31
22
|
end
|
@@ -18,15 +18,8 @@ describe "<%= ns_table_name %>/index" do
|
|
18
18
|
|
19
19
|
it "renders a list of <%= ns_table_name %>" do
|
20
20
|
render
|
21
|
-
<% unless webrat? -%>
|
22
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
23
|
-
<% end -%>
|
24
21
|
<% for attribute in output_attributes -%>
|
25
|
-
<% if webrat? -%>
|
26
|
-
expect(rendered).to have_selector("tr>td", :content => <%= value_for(attribute) %>.to_s, :count => 2)
|
27
|
-
<% else -%>
|
28
22
|
assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
|
29
|
-
<% end -%>
|
30
23
|
<% end -%>
|
31
24
|
end
|
32
25
|
end
|
@@ -12,19 +12,10 @@ describe "<%= ns_table_name %>/new" do
|
|
12
12
|
it "renders new <%= ns_file_name %> form" do
|
13
13
|
render
|
14
14
|
|
15
|
-
<% if webrat? -%>
|
16
|
-
expect(rendered).to have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
|
17
|
-
<% for attribute in output_attributes -%>
|
18
|
-
expect(form).to have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
|
19
|
-
<% end -%>
|
20
|
-
end
|
21
|
-
<% else -%>
|
22
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
23
15
|
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
|
24
16
|
<% for attribute in output_attributes -%>
|
25
17
|
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>[name=?]", "<%= ns_file_name %>[<%= attribute.name %>]"
|
26
18
|
<% end -%>
|
27
19
|
end
|
28
|
-
<% end -%>
|
29
20
|
end
|
30
21
|
end
|
@@ -14,15 +14,8 @@ describe "<%= ns_table_name %>/show" do
|
|
14
14
|
|
15
15
|
it "renders attributes in <p>" do
|
16
16
|
render
|
17
|
-
<% unless webrat? -%>
|
18
|
-
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
19
|
-
<% end -%>
|
20
17
|
<% for attribute in output_attributes -%>
|
21
|
-
<% if webrat? -%>
|
22
|
-
expect(rendered).to contain(<%= value_for(attribute) %>.to_s)
|
23
|
-
<% else -%>
|
24
18
|
expect(rendered).to match(/<%= eval(value_for(attribute)) %>/)
|
25
|
-
<% end -%>
|
26
19
|
<% end -%>
|
27
20
|
end
|
28
21
|
end
|
data/lib/rspec/rails.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rspec/core'
|
2
|
+
require 'rspec/collection_matchers'
|
2
3
|
|
3
4
|
RSpec::configure do |c|
|
4
5
|
c.backtrace_exclusion_patterns << /vendor\//
|
@@ -14,4 +15,3 @@ require 'rspec/rails/fixture_support'
|
|
14
15
|
require 'rspec/rails/mocks'
|
15
16
|
require 'rspec/rails/example'
|
16
17
|
require 'rspec/rails/vendor/capybara'
|
17
|
-
require 'rspec/rails/vendor/webrat'
|
data/lib/rspec/rails/adapters.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'delegate'
|
2
|
+
require 'active_support'
|
2
3
|
require 'active_support/concern'
|
3
4
|
|
4
5
|
module RSpec
|
@@ -8,7 +9,13 @@ module RSpec
|
|
8
9
|
require 'minitest/assertions'
|
9
10
|
Assertions = Minitest::Assertions
|
10
11
|
else
|
11
|
-
|
12
|
+
begin
|
13
|
+
require 'test/unit/assertions'
|
14
|
+
rescue LoadError
|
15
|
+
# work around for Rubinius not having a std std-lib
|
16
|
+
require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
17
|
+
require 'test/unit/assertions'
|
18
|
+
end
|
12
19
|
Assertions = Test::Unit::Assertions
|
13
20
|
end
|
14
21
|
|
@@ -36,11 +43,9 @@ module RSpec
|
|
36
43
|
assertion_modules.each do |mod|
|
37
44
|
mod.public_instance_methods.each do |method|
|
38
45
|
next if method == :method_missing || method == "method_missing"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
EOM
|
46
|
+
define_method(method.to_sym) do |*args, &block|
|
47
|
+
assertion_instance.send(method.to_sym, *args, &block)
|
48
|
+
end
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
@@ -101,10 +106,10 @@ module RSpec
|
|
101
106
|
# hooks.
|
102
107
|
def setup(*methods)
|
103
108
|
methods.each do |method|
|
104
|
-
if method.to_s =~ /^setup_(fixtures|controller_request_and_response)$/
|
105
|
-
prepend_before {
|
109
|
+
if method.to_s =~ /^setup_(with_controller|fixtures|controller_request_and_response)$/
|
110
|
+
prepend_before { __send__ method }
|
106
111
|
else
|
107
|
-
before {
|
112
|
+
before { __send__ method }
|
108
113
|
end
|
109
114
|
end
|
110
115
|
end
|
@@ -114,7 +119,7 @@ module RSpec
|
|
114
119
|
# Wraps `teardown` calls from within Rails' testing framework in
|
115
120
|
# `after` hooks.
|
116
121
|
def teardown(*methods)
|
117
|
-
methods.each { |method| after {
|
122
|
+
methods.each { |method| after { __send__ method } }
|
118
123
|
end
|
119
124
|
end
|
120
125
|
|
@@ -142,11 +147,9 @@ module RSpec
|
|
142
147
|
# @api private
|
143
148
|
def define_assertion_delegators
|
144
149
|
assertion_method_names.each do |m|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
end
|
149
|
-
CODE
|
150
|
+
define_method(m.to_sym) do |*args, &block|
|
151
|
+
assertion_delegator.send(m.to_sym, *args, &block)
|
152
|
+
end
|
150
153
|
end
|
151
154
|
end
|
152
155
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
RSpec.configure do |config|
|
2
|
-
config.add_setting :infer_base_class_for_anonymous_controllers, :default =>
|
2
|
+
config.add_setting :infer_base_class_for_anonymous_controllers, :default => true
|
3
3
|
end
|
4
4
|
|
5
5
|
module RSpec::Rails
|
@@ -55,25 +55,34 @@ module RSpec::Rails
|
|
55
55
|
# # ....
|
56
56
|
# end
|
57
57
|
def controller(base_class = nil, &body)
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
if RSpec.configuration.infer_base_class_for_anonymous_controllers?
|
59
|
+
base_class ||= controller_class
|
60
|
+
end
|
61
|
+
base_class ||= defined?(ApplicationController) ? ApplicationController : ActionController::Base
|
61
62
|
|
62
63
|
metadata[:example_group][:described_class] = Class.new(base_class) do
|
63
|
-
def self.name
|
64
|
+
def self.name
|
65
|
+
root_controller = defined?(ApplicationController) ? ApplicationController : ActionController::Base
|
66
|
+
if superclass == root_controller || superclass.abstract?
|
67
|
+
"AnonymousController"
|
68
|
+
else
|
69
|
+
superclass.to_s
|
70
|
+
end
|
71
|
+
end
|
64
72
|
end
|
65
73
|
metadata[:example_group][:described_class].class_eval(&body)
|
66
74
|
|
67
|
-
orig_routes = nil
|
68
75
|
before do
|
69
|
-
orig_routes = self.routes
|
76
|
+
@orig_routes = self.routes
|
77
|
+
resource_name = @controller.respond_to?(:controller_name) ?
|
78
|
+
@controller.controller_name.to_sym : :anonymous
|
70
79
|
self.routes = ActionDispatch::Routing::RouteSet.new.tap { |r|
|
71
|
-
r.draw { resources
|
80
|
+
r.draw { resources resource_name }
|
72
81
|
}
|
73
82
|
end
|
74
83
|
|
75
84
|
after do
|
76
|
-
self.routes = orig_routes
|
85
|
+
self.routes = @orig_routes
|
77
86
|
@orig_routes = nil
|
78
87
|
end
|
79
88
|
end
|
@@ -152,6 +152,9 @@ module RSpec::Rails
|
|
152
152
|
view.lookup_context.prefixes << _controller_path
|
153
153
|
end
|
154
154
|
|
155
|
+
# fixes bug with differing formats
|
156
|
+
view.lookup_context.view_paths.each(&:clear_cache)
|
157
|
+
|
155
158
|
controller.controller_path = _controller_path
|
156
159
|
controller.request.path_parameters[:controller] = _controller_path
|
157
160
|
controller.request.path_parameters[:action] = _inferred_action unless _inferred_action =~ /^_/
|
@@ -25,7 +25,7 @@ module RSpec::Rails::Matchers
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# @api private
|
28
|
-
def
|
28
|
+
def failure_message
|
29
29
|
[].tap do |message|
|
30
30
|
unless actual.is_a?(expected) && actual.new_record?
|
31
31
|
message << "expected #{actual.inspect} to be a new #{expected.inspect}"
|
@@ -6,11 +6,11 @@ module RSpec::Rails::Matchers
|
|
6
6
|
!actual.persisted?
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def failure_message
|
10
10
|
"expected #{actual.inspect} to be a new record, but was persisted"
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def failure_message_when_negated
|
14
14
|
"expected #{actual.inspect} to be persisted, but was a new record"
|
15
15
|
end
|
16
16
|
end
|
@@ -11,17 +11,24 @@ module RSpec::Rails::Matchers
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# @api private
|
14
|
-
def
|
14
|
+
def failure_message
|
15
15
|
message = "expected #{actual.inspect} to be valid"
|
16
|
+
|
16
17
|
if actual.respond_to?(:errors)
|
17
|
-
|
18
|
+
errors = if actual.errors.respond_to?(:full_messages)
|
19
|
+
actual.errors.full_messages
|
20
|
+
else
|
21
|
+
actual.errors
|
22
|
+
end
|
23
|
+
|
24
|
+
message << ", but got errors: #{errors.map(&:to_s).join(', ')}"
|
18
25
|
end
|
19
26
|
|
20
27
|
message
|
21
28
|
end
|
22
29
|
|
23
30
|
# @api private
|
24
|
-
def
|
31
|
+
def failure_message_when_negated
|
25
32
|
"expected #{actual.inspect} not to be valid"
|
26
33
|
end
|
27
34
|
end
|
@@ -16,12 +16,12 @@ module RSpec::Rails::Matchers
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# @api private
|
19
|
-
def
|
19
|
+
def failure_message
|
20
20
|
rescued_exception.message
|
21
21
|
end
|
22
22
|
|
23
23
|
# @api private
|
24
|
-
def
|
24
|
+
def failure_message_when_negated
|
25
25
|
"expected not to render #{expected.inspect}, but did"
|
26
26
|
end
|
27
27
|
end
|
@@ -15,12 +15,12 @@ module RSpec::Rails::Matchers
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# @api private
|
18
|
-
def
|
18
|
+
def failure_message
|
19
19
|
rescued_exception.message
|
20
20
|
end
|
21
21
|
|
22
22
|
# @api private
|
23
|
-
def
|
23
|
+
def failure_message_when_negated
|
24
24
|
"expected not to redirect to #{@expected.inspect}, but did"
|
25
25
|
end
|
26
26
|
end
|