rspec-rails 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -1
- data/Capybara.md +1 -3
- data/Changelog.md +126 -58
- data/README.md +31 -4
- data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
- data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
- data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
- data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +21 -1
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
- data/lib/generators/rspec/observer/templates/observer_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +11 -3
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +4 -3
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -4
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
- data/lib/rspec/rails.rb +1 -8
- data/lib/rspec/rails/configuration.rb +72 -0
- data/lib/rspec/rails/example.rb +0 -64
- data/lib/rspec/rails/example/controller_example_group.rb +16 -12
- data/lib/rspec/rails/example/feature_example_group.rb +0 -2
- data/lib/rspec/rails/example/helper_example_group.rb +0 -2
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -1
- data/lib/rspec/rails/example/model_example_group.rb +0 -4
- data/lib/rspec/rails/example/request_example_group.rb +0 -2
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/view_example_group.rb +1 -2
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/fixture_support.rb +0 -8
- data/lib/rspec/rails/matchers.rb +1 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +355 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
- data/lib/rspec/rails/tasks/rspec.rake +12 -5
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +6 -34
- metadata +42 -316
- metadata.gz.sig +0 -0
- data/features/Generators.md +0 -25
- data/features/GettingStarted.md +0 -84
- data/features/README.md +0 -48
- data/features/RailsVersions.md +0 -4
- data/features/Transactions.md +0 -84
- data/features/Upgrade.md +0 -121
- data/features/controller_specs/Cookies.md +0 -57
- data/features/controller_specs/README.md +0 -45
- data/features/controller_specs/anonymous_controller.feature +0 -436
- data/features/controller_specs/bypass_rescue.feature +0 -75
- data/features/controller_specs/controller_spec.feature +0 -58
- data/features/controller_specs/engine_routes.feature +0 -51
- data/features/controller_specs/isolation_from_views.feature +0 -87
- data/features/controller_specs/render_views.feature +0 -114
- data/features/directory_structure.feature +0 -71
- data/features/feature_specs/feature_spec.feature +0 -35
- data/features/helper_specs/helper_spec.feature +0 -122
- data/features/mailer_specs/url_helpers.feature +0 -38
- data/features/matchers/README.md +0 -18
- data/features/matchers/new_record_matcher.feature +0 -41
- data/features/matchers/redirect_to_matcher.feature +0 -40
- data/features/matchers/relation_match_array.feature +0 -27
- data/features/matchers/render_template_matcher.feature +0 -49
- data/features/mocks/mock_model.feature +0 -147
- data/features/mocks/stub_model.feature +0 -58
- data/features/model_specs/README.md +0 -21
- data/features/model_specs/errors_on.feature +0 -51
- data/features/model_specs/records.feature +0 -27
- data/features/model_specs/transactional_examples.feature +0 -109
- data/features/request_specs/request_spec.feature +0 -49
- data/features/routing_specs/README.md +0 -16
- data/features/routing_specs/be_routable_matcher.feature +0 -80
- data/features/routing_specs/engine_routes.feature +0 -38
- data/features/routing_specs/named_routes.feature +0 -18
- data/features/routing_specs/route_to_matcher.feature +0 -90
- data/features/step_definitions/additional_cli_steps.rb +0 -4
- data/features/step_definitions/model_steps.rb +0 -3
- data/features/support/capybara.rb +0 -7
- data/features/support/env.rb +0 -53
- data/features/support/rails_versions.rb +0 -4
- data/features/support/rubinius.rb +0 -6
- data/features/view_specs/inferred_controller_path.feature +0 -45
- data/features/view_specs/stub_template.feature +0 -51
- data/features/view_specs/view_spec.feature +0 -206
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/mocks.rb +0 -272
- data/lib/rspec/rails/vendor/webrat.rb +0 -33
- data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
- data/spec/generators/rspec/feature/feature_generator_spec.rb +0 -43
- data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
- data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
- data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -32
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
- data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
- data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
- data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
- data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
- data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
- data/spec/rspec/rails/configuration_spec.rb +0 -26
- data/spec/rspec/rails/deprecations_spec.rb +0 -18
- data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -159
- data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
- data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
- data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
- data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
- data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
- data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
- data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
- data/spec/rspec/rails/fixture_support_spec.rb +0 -17
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
- data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
- data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -73
- data/spec/rspec/rails/matchers/has_spec.rb +0 -29
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
- data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
- data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -400
- data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
- data/spec/rspec/rails/view_rendering_spec.rb +0 -111
- data/spec/spec_helper.rb +0 -33
- data/spec/support/ar_classes.rb +0 -42
- data/spec/support/helpers.rb +0 -34
- data/spec/support/matchers.rb +0 -9
- data/spec/support/null_object.rb +0 -6
@@ -1,26 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "configuration" do
|
4
|
-
before do
|
5
|
-
@orig_render_views = RSpec.configuration.render_views?
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
RSpec.configuration.render_views = @orig_render_views
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#render_views?" do
|
13
|
-
it "is false by default" do
|
14
|
-
expect(RSpec.configuration.render_views?).to be_falsey
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#render_views" do
|
19
|
-
it "sets render_views? to return true" do
|
20
|
-
RSpec.configuration.render_views = false
|
21
|
-
RSpec.configuration.render_views
|
22
|
-
|
23
|
-
expect(RSpec.configuration.render_views?).to be_truthy
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "rspec-rails-2 deprecations" do
|
4
|
-
context "controller specs" do
|
5
|
-
describe "::integrate_views" do
|
6
|
-
let(:group) do
|
7
|
-
RSpec::Core::ExampleGroup.describe do
|
8
|
-
include RSpec::Rails::ControllerExampleGroup
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "is deprecated" do
|
13
|
-
expect(RSpec).to receive(:deprecate)
|
14
|
-
group.integrate_views
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,159 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class ::ApplicationController
|
4
|
-
def self.abstract?; false; end
|
5
|
-
end
|
6
|
-
|
7
|
-
module RSpec::Rails
|
8
|
-
describe ControllerExampleGroup do
|
9
|
-
it { is_expected.to be_included_in_files_in('./spec/controllers/') }
|
10
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\controllers\\') }
|
11
|
-
|
12
|
-
let(:group) do
|
13
|
-
RSpec::Core::ExampleGroup.describe do
|
14
|
-
include ControllerExampleGroup
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "includes routing matchers" do
|
19
|
-
expect(group.included_modules).to include(RSpec::Rails::Matchers::RoutingMatchers)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "adds :type => :controller to the metadata" do
|
23
|
-
expect(group.metadata[:type]).to eq(:controller)
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with implicit subject" do
|
27
|
-
it "uses the controller as the subject" do
|
28
|
-
controller = double('controller')
|
29
|
-
example = group.new
|
30
|
-
allow(example).to receive_messages(:controller => controller)
|
31
|
-
expect(example.subject).to eq(controller)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with explicit subject" do
|
36
|
-
it "uses the specified subject instead of the controller" do
|
37
|
-
group.subject { 'explicit' }
|
38
|
-
example = group.new
|
39
|
-
expect(example.subject).to eq('explicit')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#controller" do
|
44
|
-
before do
|
45
|
-
group.class_eval do
|
46
|
-
controller(Class.new) { }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it "delegates named route helpers to the underlying controller" do
|
51
|
-
controller = double('controller')
|
52
|
-
allow(controller).to receive(:foos_url).and_return('http://test.host/foos')
|
53
|
-
|
54
|
-
example = group.new
|
55
|
-
allow(example).to receive_messages(:controller => controller)
|
56
|
-
|
57
|
-
# As in the routing example spec, this is pretty invasive, but not sure
|
58
|
-
# how to do it any other way as the correct operation relies on before
|
59
|
-
# hooks
|
60
|
-
routes = ActionDispatch::Routing::RouteSet.new
|
61
|
-
routes.draw { resources :foos }
|
62
|
-
example.instance_variable_set(:@orig_routes, routes)
|
63
|
-
|
64
|
-
expect(example.foos_url).to eq('http://test.host/foos')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "#bypass_rescue" do
|
69
|
-
it "overrides the rescue_with_handler method on the controller to raise submitted error" do
|
70
|
-
example = group.new
|
71
|
-
example.instance_variable_set("@controller", Class.new { def rescue_with_handler(e); end }.new)
|
72
|
-
example.bypass_rescue
|
73
|
-
expect do
|
74
|
-
example.controller.rescue_with_handler(RuntimeError.new("foo"))
|
75
|
-
end.to raise_error("foo")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "with inferred anonymous controller" do
|
80
|
-
before do
|
81
|
-
allow(group).to receive(:controller_class).and_return(Class.new)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "defaults to inferring anonymous controller class" do
|
85
|
-
expect(RSpec.configuration.infer_base_class_for_anonymous_controllers).to be_truthy
|
86
|
-
end
|
87
|
-
|
88
|
-
context "when infer_base_class_for_anonymous_controllers is true" do
|
89
|
-
before do
|
90
|
-
allow(RSpec.configuration).to receive(:infer_base_class_for_anonymous_controllers?).and_return(true)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "infers the anonymous controller class" do
|
94
|
-
group.controller { }
|
95
|
-
|
96
|
-
controller_class = group.metadata[:example_group][:described_class]
|
97
|
-
expect(controller_class.superclass).to eq(group.controller_class)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "infers the anonymous controller class when no ApplicationController is present" do
|
101
|
-
hide_const '::ApplicationController'
|
102
|
-
group.controller { }
|
103
|
-
|
104
|
-
controller_class = group.metadata[:example_group][:described_class]
|
105
|
-
expect(controller_class.superclass).to eq(group.controller_class)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "when infer_base_class_for_anonymous_controllers is false" do
|
110
|
-
before do
|
111
|
-
allow(RSpec.configuration).to receive(:infer_base_class_for_anonymous_controllers?).and_return(false)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "sets the anonymous controller class to ApplicationController" do
|
115
|
-
group.controller { }
|
116
|
-
|
117
|
-
controller_class = group.metadata[:example_group][:described_class]
|
118
|
-
expect(controller_class.superclass).to eq(ApplicationController)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "sets the anonymous controller class to ActiveController::Base when no ApplicationController is present" do
|
122
|
-
hide_const '::ApplicationController'
|
123
|
-
group.controller { }
|
124
|
-
|
125
|
-
controller_class = group.metadata[:example_group][:described_class]
|
126
|
-
expect(controller_class.superclass).to eq(ActionController::Base)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "controller name" do
|
132
|
-
let(:controller_class) { group.metadata[:example_group][:described_class] }
|
133
|
-
|
134
|
-
it "sets the name as AnonymousController if it's anonymous" do
|
135
|
-
group.controller { }
|
136
|
-
expect(controller_class.name).to eq "AnonymousController"
|
137
|
-
end
|
138
|
-
|
139
|
-
it "sets the name according to defined controller if it is not anonymous" do
|
140
|
-
stub_const "FoosController", Class.new(::ApplicationController)
|
141
|
-
group.controller(FoosController) { }
|
142
|
-
expect(controller_class.name).to eq "FoosController"
|
143
|
-
end
|
144
|
-
|
145
|
-
it "sets name as AnonymousController if defined as ApplicationController" do
|
146
|
-
group.controller(ApplicationController) { }
|
147
|
-
expect(controller_class.name).to eq "AnonymousController"
|
148
|
-
end
|
149
|
-
|
150
|
-
it "sets name as AnonymousController the controller is abstract" do
|
151
|
-
abstract_controller = Class.new(::ApplicationController)
|
152
|
-
def abstract_controller.abstract?; true; end
|
153
|
-
|
154
|
-
group.controller(abstract_controller) { }
|
155
|
-
expect(controller_class.name).to eq "AnonymousController"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Rails
|
4
|
-
describe FeatureExampleGroup do
|
5
|
-
it { is_expected.to be_included_in_files_in('./spec/features/') }
|
6
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\features\\') }
|
7
|
-
|
8
|
-
it "adds :type => :feature to the metadata" do
|
9
|
-
group = RSpec::Core::ExampleGroup.describe do
|
10
|
-
include FeatureExampleGroup
|
11
|
-
end
|
12
|
-
|
13
|
-
expect(group.metadata[:type]).to eq(:feature)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "includes Rails route helpers" do
|
17
|
-
Rails.application.routes.draw do
|
18
|
-
get "/foo", :as => :foo, :to => "foo#bar"
|
19
|
-
end
|
20
|
-
|
21
|
-
group = RSpec::Core::ExampleGroup.describe do
|
22
|
-
include FeatureExampleGroup
|
23
|
-
end
|
24
|
-
|
25
|
-
expect(group.new.foo_path).to eq("/foo")
|
26
|
-
expect(group.new.foo_url).to eq("http://www.example.com/foo")
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#visit" do
|
30
|
-
it "raises an error informing about missing Capybara" do
|
31
|
-
group = RSpec::Core::ExampleGroup.describe do
|
32
|
-
include FeatureExampleGroup
|
33
|
-
end
|
34
|
-
|
35
|
-
expect {
|
36
|
-
group.new.visit('/foobar')
|
37
|
-
}.to raise_error(/Capybara not loaded/)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "is resistant to load order errors" do
|
41
|
-
capybara = Module.new do
|
42
|
-
def visit(url)
|
43
|
-
"success: #{url}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
group = RSpec::Core::ExampleGroup.describe do
|
48
|
-
include capybara
|
49
|
-
include FeatureExampleGroup
|
50
|
-
end
|
51
|
-
|
52
|
-
expect(group.new.visit("/foo")).to eq("success: /foo")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Rails
|
4
|
-
describe HelperExampleGroup do
|
5
|
-
module ::FoosHelper; end
|
6
|
-
subject { HelperExampleGroup }
|
7
|
-
|
8
|
-
it { is_expected.to be_included_in_files_in('./spec/helpers/') }
|
9
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\helpers\\') }
|
10
|
-
|
11
|
-
it "provides a controller_path based on the helper module's name" do
|
12
|
-
example = double
|
13
|
-
example.stub_chain(:example_group, :described_class) { FoosHelper }
|
14
|
-
|
15
|
-
helper_spec = Object.new.extend HelperExampleGroup
|
16
|
-
expect(helper_spec.__send__(:_controller_path, example)).to eq("foos")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "adds :type => :helper to the metadata" do
|
20
|
-
group = RSpec::Core::ExampleGroup.describe do
|
21
|
-
include HelperExampleGroup
|
22
|
-
end
|
23
|
-
expect(group.metadata[:type]).to eq(:helper)
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#helper" do
|
27
|
-
it "returns the instance of AV::Base provided by AV::TC::Behavior" do
|
28
|
-
helper_spec = Object.new.extend HelperExampleGroup
|
29
|
-
expect(helper_spec).to receive(:view_assigns)
|
30
|
-
av_tc_b_view = double('_view')
|
31
|
-
expect(av_tc_b_view).to receive(:assign)
|
32
|
-
allow(helper_spec).to receive(:_view) { av_tc_b_view }
|
33
|
-
expect(helper_spec.helper).to eq(av_tc_b_view)
|
34
|
-
end
|
35
|
-
|
36
|
-
before do
|
37
|
-
Object.const_set(:ApplicationHelper, Module.new)
|
38
|
-
end
|
39
|
-
|
40
|
-
after do
|
41
|
-
Object.__send__(:remove_const, :ApplicationHelper)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "includes ApplicationHelper" do
|
45
|
-
group = RSpec::Core::ExampleGroup.describe do
|
46
|
-
include HelperExampleGroup
|
47
|
-
def _view
|
48
|
-
ActionView::Base.new
|
49
|
-
end
|
50
|
-
end
|
51
|
-
expect(group.new.helper).to be_kind_of(ApplicationHelper)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe HelperExampleGroup::ClassMethods do
|
57
|
-
describe "determine_default_helper_class" do
|
58
|
-
it "returns the helper module passed to describe" do
|
59
|
-
helper_spec = Object.new.extend HelperExampleGroup::ClassMethods
|
60
|
-
allow(helper_spec).to receive(:described_class) { FoosHelper }
|
61
|
-
expect(helper_spec.determine_default_helper_class("ignore this")).
|
62
|
-
to eq(FoosHelper)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Rails
|
4
|
-
describe MailerExampleGroup do
|
5
|
-
module ::Rails; end
|
6
|
-
before do
|
7
|
-
Rails.stub_chain(:application, :routes, :url_helpers).and_return(Rails)
|
8
|
-
Rails.stub_chain(:configuration, :action_mailer, :default_url_options).and_return({})
|
9
|
-
end
|
10
|
-
|
11
|
-
it { is_expected.to be_included_in_files_in('./spec/mailers/') }
|
12
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\mailers\\') }
|
13
|
-
|
14
|
-
it "adds :type => :mailer to the metadata" do
|
15
|
-
group = RSpec::Core::ExampleGroup.describe do
|
16
|
-
include MailerExampleGroup
|
17
|
-
end
|
18
|
-
expect(group.metadata[:type]).to eq(:mailer)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Rails
|
4
|
-
describe ModelExampleGroup do
|
5
|
-
it { is_expected.to be_included_in_files_in('./spec/models/') }
|
6
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\models\\') }
|
7
|
-
|
8
|
-
it "adds :type => :model to the metadata" do
|
9
|
-
group = RSpec::Core::ExampleGroup.describe do
|
10
|
-
include ModelExampleGroup
|
11
|
-
end
|
12
|
-
expect(group.metadata[:type]).to eq(:model)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Rails
|
4
|
-
describe RequestExampleGroup do
|
5
|
-
it { is_expected.to be_included_in_files_in('./spec/requests/') }
|
6
|
-
it { is_expected.to be_included_in_files_in('./spec/integration/') }
|
7
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\requests\\') }
|
8
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\integration\\') }
|
9
|
-
|
10
|
-
it "adds :type => :request to the metadata" do
|
11
|
-
group = RSpec::Core::ExampleGroup.describe do
|
12
|
-
include RequestExampleGroup
|
13
|
-
end
|
14
|
-
expect(group.metadata[:type]).to eq(:request)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Rails
|
4
|
-
describe RoutingExampleGroup do
|
5
|
-
it { is_expected.to be_included_in_files_in('./spec/routing/') }
|
6
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\routing\\') }
|
7
|
-
|
8
|
-
it "adds :type => :routing to the metadata" do
|
9
|
-
group = RSpec::Core::ExampleGroup.describe do
|
10
|
-
include RoutingExampleGroup
|
11
|
-
end
|
12
|
-
expect(group.metadata[:type]).to eq(:routing)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "named routes" do
|
16
|
-
it "delegates them to the route_set" do
|
17
|
-
group = RSpec::Core::ExampleGroup.describe do
|
18
|
-
include RoutingExampleGroup
|
19
|
-
end
|
20
|
-
|
21
|
-
example = group.new
|
22
|
-
|
23
|
-
# Yes, this is quite invasive
|
24
|
-
url_helpers = double('url_helpers', :foo_path => "foo")
|
25
|
-
routes = double('routes', :url_helpers => url_helpers)
|
26
|
-
allow(example).to receive_messages(:routes => routes)
|
27
|
-
|
28
|
-
expect(example.foo_path).to eq("foo")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,235 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Rails
|
4
|
-
describe ViewExampleGroup do
|
5
|
-
it { is_expected.to be_included_in_files_in('./spec/views/') }
|
6
|
-
it { is_expected.to be_included_in_files_in('.\\spec\\views\\') }
|
7
|
-
|
8
|
-
it "adds :type => :view to the metadata" do
|
9
|
-
group = RSpec::Core::ExampleGroup.describe do
|
10
|
-
include ViewExampleGroup
|
11
|
-
end
|
12
|
-
expect(group.metadata[:type]).to eq(:view)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'automatic inclusion of helpers' do
|
16
|
-
module ::ThingsHelper; end
|
17
|
-
module ::Namespaced; module ThingsHelper; end; end
|
18
|
-
|
19
|
-
it 'includes the helper with the same name' do
|
20
|
-
group = RSpec::Core::ExampleGroup.describe 'things/show.html.erb'
|
21
|
-
expect(group).to receive(:helper).with(ThingsHelper)
|
22
|
-
group.class_eval do
|
23
|
-
include ViewExampleGroup
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'includes the namespaced helper with the same name' do
|
28
|
-
group = RSpec::Core::ExampleGroup.describe 'namespaced/things/show.html.erb'
|
29
|
-
expect(group).to receive(:helper).with(Namespaced::ThingsHelper)
|
30
|
-
group.class_eval do
|
31
|
-
include ViewExampleGroup
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'operates normally when no helper with the same name exists' do
|
36
|
-
raise 'unexpected constant found' if Object.const_defined?('ClocksHelper')
|
37
|
-
expect {
|
38
|
-
RSpec::Core::ExampleGroup.describe 'clocks/show.html.erb' do
|
39
|
-
include ViewExampleGroup
|
40
|
-
end
|
41
|
-
}.not_to raise_error
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'application helper exists' do
|
45
|
-
before do
|
46
|
-
if !Object.const_defined? 'ApplicationHelper'
|
47
|
-
module ::ApplicationHelper; end
|
48
|
-
@application_helper_defined = true
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
after do
|
53
|
-
if @application_helper_defined
|
54
|
-
Object.__send__ :remove_const, 'ApplicationHelper'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'includes the application helper' do
|
59
|
-
group = RSpec::Core::Example.describe 'bars/new.html.erb'
|
60
|
-
expect(group).to receive(:helper).with(ApplicationHelper)
|
61
|
-
group.class_eval do
|
62
|
-
include ViewExampleGroup
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'no application helper exists' do
|
68
|
-
before do
|
69
|
-
if Object.const_defined? 'ApplicationHelper'
|
70
|
-
@application_helper = ApplicationHelper
|
71
|
-
Object.__send__ :remove_const, 'ApplicationHelper'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
after do
|
76
|
-
if @application_helper
|
77
|
-
ApplicationHelper = @application_helper
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'operates normally' do
|
82
|
-
expect {
|
83
|
-
RSpec::Core::ExampleGroup.describe 'foos/edit.html.erb' do
|
84
|
-
include ViewExampleGroup
|
85
|
-
end
|
86
|
-
}.not_to raise_error
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#render" do
|
92
|
-
let(:view_spec) do
|
93
|
-
Class.new do
|
94
|
-
module Local
|
95
|
-
def received
|
96
|
-
@received ||= []
|
97
|
-
end
|
98
|
-
def render(options={}, local_assigns={}, &block)
|
99
|
-
received << [options, local_assigns, block]
|
100
|
-
end
|
101
|
-
def _assigns
|
102
|
-
{}
|
103
|
-
end
|
104
|
-
end
|
105
|
-
include Local
|
106
|
-
include ViewExampleGroup::ExampleMethods
|
107
|
-
end.new
|
108
|
-
end
|
109
|
-
|
110
|
-
context "given no input" do
|
111
|
-
it "sends render(:template => (described file)) to the view" do
|
112
|
-
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new" }
|
113
|
-
view_spec.render
|
114
|
-
expect(view_spec.received.first).to eq([{:template => "widgets/new"},{}, nil])
|
115
|
-
end
|
116
|
-
|
117
|
-
it "converts the filename components into render options" do
|
118
|
-
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.html.erb" }
|
119
|
-
view_spec.render
|
120
|
-
|
121
|
-
if ::Rails::VERSION::STRING >= '3.2'
|
122
|
-
expect(view_spec.received.first).to eq([{:template => "widgets/new", :locales=>['en'], :formats=>['html'], :handlers=>['erb']}, {}, nil])
|
123
|
-
else
|
124
|
-
expect(view_spec.received.first).to eq([{:template => "widgets/new.en.html.erb"}, {}, nil])
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "given a string" do
|
130
|
-
it "sends string as the first arg to render" do
|
131
|
-
view_spec.render('arbitrary/path')
|
132
|
-
expect(view_spec.received.first).to eq(["arbitrary/path", {}, nil])
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "given a hash" do
|
137
|
-
it "sends the hash as the first arg to render" do
|
138
|
-
view_spec.render(:foo => 'bar')
|
139
|
-
expect(view_spec.received.first).to eq([{:foo => "bar"}, {}, nil])
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe '#params' do
|
145
|
-
let(:view_spec) do
|
146
|
-
Class.new do
|
147
|
-
include ViewExampleGroup::ExampleMethods
|
148
|
-
def controller
|
149
|
-
@controller ||= Object.new
|
150
|
-
end
|
151
|
-
end.new
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'delegates to the controller' do
|
155
|
-
expect(view_spec.controller).to receive(:params).and_return({})
|
156
|
-
view_spec.params[:foo] = 1
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "#_controller_path" do
|
161
|
-
let(:view_spec) do
|
162
|
-
Class.new do
|
163
|
-
include ViewExampleGroup::ExampleMethods
|
164
|
-
end.new
|
165
|
-
end
|
166
|
-
context "with a common _default_file_to_render" do
|
167
|
-
it "it returns the directory" do
|
168
|
-
allow(view_spec).to receive(:_default_file_to_render).
|
169
|
-
and_return("things/new.html.erb")
|
170
|
-
expect(view_spec.__send__(:_controller_path)).
|
171
|
-
to eq("things")
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context "with a nested _default_file_to_render" do
|
176
|
-
it "it returns the directory path" do
|
177
|
-
allow(view_spec).to receive(:_default_file_to_render).
|
178
|
-
and_return("admin/things/new.html.erb")
|
179
|
-
expect(view_spec.__send__(:_controller_path)).
|
180
|
-
to eq("admin/things")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe "#view" do
|
186
|
-
let(:view_spec) do
|
187
|
-
Class.new do
|
188
|
-
include ViewExampleGroup::ExampleMethods
|
189
|
-
end.new
|
190
|
-
end
|
191
|
-
|
192
|
-
it "delegates to _view" do
|
193
|
-
view = double("view")
|
194
|
-
allow(view_spec).to receive(:_view) { view }
|
195
|
-
expect(view_spec.view).to eq(view)
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'is accessible to hooks' do
|
199
|
-
with_isolated_config do
|
200
|
-
run_count = 0
|
201
|
-
RSpec.configuration.before(:each, :type => :view) do
|
202
|
-
allow(view).to receive(:a_stubbed_helper) { :value }
|
203
|
-
run_count += 1
|
204
|
-
end
|
205
|
-
group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do
|
206
|
-
specify { true }
|
207
|
-
end
|
208
|
-
group.run NullObject.new
|
209
|
-
expect(run_count).to eq 1
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "#template" do
|
215
|
-
let(:view_spec) do
|
216
|
-
Class.new do
|
217
|
-
include ViewExampleGroup::ExampleMethods
|
218
|
-
def _view; end
|
219
|
-
end.new
|
220
|
-
end
|
221
|
-
|
222
|
-
before { allow(RSpec).to receive(:deprecate) }
|
223
|
-
|
224
|
-
it "is deprecated" do
|
225
|
-
expect(RSpec).to receive(:deprecate)
|
226
|
-
view_spec.template
|
227
|
-
end
|
228
|
-
|
229
|
-
it "delegates to #view" do
|
230
|
-
expect(view_spec).to receive(:view)
|
231
|
-
view_spec.template
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|