rspec-rails 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +57 -0
- data/Manifest.txt +158 -0
- data/README.txt +81 -0
- data/Rakefile +39 -0
- data/UPGRADE +7 -0
- data/generators/rspec/CHANGES +1 -0
- data/generators/rspec/rspec_generator.rb +40 -0
- data/generators/rspec/templates/all_stories.rb +4 -0
- data/generators/rspec/templates/previous_failures.txt +0 -0
- data/generators/rspec/templates/rcov.opts +2 -0
- data/generators/rspec/templates/rspec.rake +132 -0
- data/generators/rspec/templates/script/autospec +3 -0
- data/generators/rspec/templates/script/spec +4 -0
- data/generators/rspec/templates/script/spec_server +116 -0
- data/generators/rspec/templates/spec.opts +4 -0
- data/generators/rspec/templates/spec_helper.rb +47 -0
- data/generators/rspec/templates/stories_helper.rb +3 -0
- data/generators/rspec_controller/USAGE +33 -0
- data/generators/rspec_controller/rspec_controller_generator.rb +49 -0
- data/generators/rspec_controller/templates/controller_spec.rb +25 -0
- data/generators/rspec_controller/templates/helper_spec.rb +11 -0
- data/generators/rspec_controller/templates/view_spec.rb +12 -0
- data/generators/rspec_default_values.rb +19 -0
- data/generators/rspec_model/USAGE +18 -0
- data/generators/rspec_model/rspec_model_generator.rb +35 -0
- data/generators/rspec_model/templates/model_spec.rb +15 -0
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
- data/generators/rspec_scaffold/templates/controller_spec.rb +173 -0
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +26 -0
- data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +26 -0
- data/generators/rspec_scaffold/templates/routing_spec.rb +59 -0
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
- data/init.rb +9 -0
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/rails_rspec.rb +76 -0
- data/lib/spec/rails.rb +15 -0
- data/lib/spec/rails/example.rb +47 -0
- data/lib/spec/rails/example/assigns_hash_proxy.rb +43 -0
- data/lib/spec/rails/example/controller_example_group.rb +256 -0
- data/lib/spec/rails/example/cookies_proxy.rb +25 -0
- data/lib/spec/rails/example/functional_example_group.rb +87 -0
- data/lib/spec/rails/example/helper_example_group.rb +166 -0
- data/lib/spec/rails/example/model_example_group.rb +14 -0
- data/lib/spec/rails/example/rails_example_group.rb +33 -0
- data/lib/spec/rails/example/render_observer.rb +93 -0
- data/lib/spec/rails/example/view_example_group.rb +183 -0
- data/lib/spec/rails/extensions.rb +12 -0
- data/lib/spec/rails/extensions/action_controller/base.rb +14 -0
- data/lib/spec/rails/extensions/action_controller/rescue.rb +21 -0
- data/lib/spec/rails/extensions/action_controller/test_response.rb +11 -0
- data/lib/spec/rails/extensions/action_view/base.rb +31 -0
- data/lib/spec/rails/extensions/active_record/base.rb +30 -0
- data/lib/spec/rails/extensions/object.rb +5 -0
- data/lib/spec/rails/extensions/spec/example/configuration.rb +71 -0
- data/lib/spec/rails/extensions/spec/matchers/have.rb +21 -0
- data/lib/spec/rails/interop/testcase.rb +14 -0
- data/lib/spec/rails/matchers.rb +31 -0
- data/lib/spec/rails/matchers/assert_select.rb +131 -0
- data/lib/spec/rails/matchers/change.rb +11 -0
- data/lib/spec/rails/matchers/have_text.rb +57 -0
- data/lib/spec/rails/matchers/include_text.rb +54 -0
- data/lib/spec/rails/matchers/redirect_to.rb +113 -0
- data/lib/spec/rails/matchers/render_template.rb +90 -0
- data/lib/spec/rails/mocks.rb +132 -0
- data/lib/spec/rails/story_adapter.rb +79 -0
- data/lib/spec/rails/version.rb +15 -0
- data/spec/rails/autotest/mappings_spec.rb +36 -0
- data/spec/rails/example/assigns_hash_proxy_spec.rb +65 -0
- data/spec/rails/example/configuration_spec.rb +83 -0
- data/spec/rails/example/controller_isolation_spec.rb +62 -0
- data/spec/rails/example/controller_spec_spec.rb +272 -0
- data/spec/rails/example/cookies_proxy_spec.rb +74 -0
- data/spec/rails/example/example_group_factory_spec.rb +112 -0
- data/spec/rails/example/helper_spec_spec.rb +161 -0
- data/spec/rails/example/model_spec_spec.rb +18 -0
- data/spec/rails/example/shared_behaviour_spec.rb +16 -0
- data/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
- data/spec/rails/example/view_spec_spec.rb +280 -0
- data/spec/rails/extensions/action_controller_rescue_action_spec.rb +54 -0
- data/spec/rails/extensions/action_view_base_spec.rb +48 -0
- data/spec/rails/extensions/active_record_spec.rb +14 -0
- data/spec/rails/interop/testcase_spec.rb +66 -0
- data/spec/rails/matchers/assert_select_spec.rb +814 -0
- data/spec/rails/matchers/description_generation_spec.rb +37 -0
- data/spec/rails/matchers/errors_on_spec.rb +13 -0
- data/spec/rails/matchers/have_text_spec.rb +62 -0
- data/spec/rails/matchers/include_text_spec.rb +64 -0
- data/spec/rails/matchers/redirect_to_spec.rb +209 -0
- data/spec/rails/matchers/render_template_spec.rb +176 -0
- data/spec/rails/matchers/should_change_spec.rb +15 -0
- data/spec/rails/mocks/ar_classes.rb +10 -0
- data/spec/rails/mocks/mock_model_spec.rb +106 -0
- data/spec/rails/mocks/stub_model_spec.rb +80 -0
- data/spec/rails/sample_modified_fixture.rb +8 -0
- data/spec/rails/sample_spec.rb +8 -0
- data/spec/rails/spec_server_spec.rb +96 -0
- data/spec/rails/spec_spec.rb +11 -0
- data/spec/rails_suite.rb +7 -0
- data/spec/spec_helper.rb +57 -0
- data/spec_resources/controllers/action_view_base_spec_controller.rb +2 -0
- data/spec_resources/controllers/controller_spec_controller.rb +94 -0
- data/spec_resources/controllers/redirect_spec_controller.rb +59 -0
- data/spec_resources/controllers/render_spec_controller.rb +30 -0
- data/spec_resources/controllers/rjs_spec_controller.rb +58 -0
- data/spec_resources/helpers/explicit_helper.rb +38 -0
- data/spec_resources/helpers/more_explicit_helper.rb +5 -0
- data/spec_resources/helpers/plugin_application_helper.rb +6 -0
- data/spec_resources/helpers/view_spec_helper.rb +13 -0
- data/spec_resources/views/controller_spec/_partial.rhtml +0 -0
- data/spec_resources/views/controller_spec/action_setting_flash_after_session_reset.rhtml +1 -0
- data/spec_resources/views/controller_spec/action_setting_flash_before_session_reset.rhtml +1 -0
- data/spec_resources/views/controller_spec/action_setting_the_assigns_hash.rhtml +0 -0
- data/spec_resources/views/controller_spec/action_with_errors_in_template.rhtml +1 -0
- data/spec_resources/views/controller_spec/action_with_template.rhtml +1 -0
- data/spec_resources/views/layouts/application.rhtml +0 -0
- data/spec_resources/views/layouts/simple.rhtml +0 -0
- data/spec_resources/views/objects/_object.html.erb +1 -0
- data/spec_resources/views/render_spec/_a_partial.rhtml +0 -0
- data/spec_resources/views/render_spec/action_with_alternate_layout.rhtml +0 -0
- data/spec_resources/views/render_spec/some_action.js.rjs +1 -0
- data/spec_resources/views/render_spec/some_action.rhtml +0 -0
- data/spec_resources/views/render_spec/some_action.rjs +1 -0
- data/spec_resources/views/rjs_spec/_replacement_partial.rhtml +1 -0
- data/spec_resources/views/rjs_spec/hide_div.rjs +1 -0
- data/spec_resources/views/rjs_spec/hide_page_element.rjs +1 -0
- data/spec_resources/views/rjs_spec/insert_html.rjs +1 -0
- data/spec_resources/views/rjs_spec/replace.rjs +1 -0
- data/spec_resources/views/rjs_spec/replace_html.rjs +1 -0
- data/spec_resources/views/rjs_spec/replace_html_with_partial.rjs +1 -0
- data/spec_resources/views/rjs_spec/visual_effect.rjs +1 -0
- data/spec_resources/views/rjs_spec/visual_toggle_effect.rjs +1 -0
- data/spec_resources/views/tag_spec/no_tags.rhtml +1 -0
- data/spec_resources/views/tag_spec/single_div_with_no_attributes.rhtml +1 -0
- data/spec_resources/views/tag_spec/single_div_with_one_attribute.rhtml +1 -0
- data/spec_resources/views/view_spec/_partial.rhtml +2 -0
- data/spec_resources/views/view_spec/_partial_used_twice.rhtml +0 -0
- data/spec_resources/views/view_spec/_partial_with_local_variable.rhtml +1 -0
- data/spec_resources/views/view_spec/_partial_with_sub_partial.rhtml +1 -0
- data/spec_resources/views/view_spec/_spacer.rhtml +1 -0
- data/spec_resources/views/view_spec/accessor.rhtml +5 -0
- data/spec_resources/views/view_spec/block_helper.rhtml +3 -0
- data/spec_resources/views/view_spec/entry_form.rhtml +2 -0
- data/spec_resources/views/view_spec/explicit_helper.rhtml +2 -0
- data/spec_resources/views/view_spec/foo/show.rhtml +1 -0
- data/spec_resources/views/view_spec/implicit_helper.rhtml +2 -0
- data/spec_resources/views/view_spec/multiple_helpers.rhtml +3 -0
- data/spec_resources/views/view_spec/should_not_receive.rhtml +3 -0
- data/spec_resources/views/view_spec/template_with_partial.rhtml +5 -0
- data/spec_resources/views/view_spec/template_with_partial_using_collection.rhtml +3 -0
- data/spec_resources/views/view_spec/template_with_partial_with_array.rhtml +1 -0
- data/stories/all.rb +10 -0
- data/stories/configuration/stories.rb +5 -0
- data/stories/helper.rb +6 -0
- data/stories/steps/people.rb +8 -0
- data/stories/transactions_should_rollback +15 -0
- data/stories/transactions_should_rollback.rb +25 -0
- metadata +234 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. .. lib autotest rails_rspec])
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. .. .. rspec spec autotest_matchers])
|
4
|
+
|
5
|
+
describe Autotest::RailsRspec, "file mapping" do
|
6
|
+
before(:each) do
|
7
|
+
@autotest = Autotest::RailsRspec.new
|
8
|
+
@autotest.hook :initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should map model example to model" do
|
12
|
+
@autotest.should map_specs(['spec/models/thing_spec.rb']).
|
13
|
+
to('app/models/thing.rb')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should map controller example to controller" do
|
17
|
+
@autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
|
18
|
+
to('app/controllers/things_controller.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should map view.rhtml" do
|
22
|
+
@autotest.should map_specs(['spec/views/things/index.rhtml_spec.rb']).
|
23
|
+
to('app/views/things/index.rhtml')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should map view.rhtml with underscores in example filename" do
|
27
|
+
@autotest.should map_specs(['spec/views/things/index_rhtml_spec.rb']).
|
28
|
+
to('app/views/things/index.rhtml')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should map view.html.erb" do
|
32
|
+
@autotest.should map_specs(['spec/views/things/index.html.erb_spec.rb']).
|
33
|
+
to('app/views/things/index.html.erb')
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe "AssignsHashProxy" do
|
4
|
+
def orig_assigns
|
5
|
+
@object.assigns
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@object = Class.new do
|
10
|
+
attr_accessor :assigns
|
11
|
+
end.new
|
12
|
+
@object.assigns = Hash.new
|
13
|
+
@proxy = Spec::Rails::Example::AssignsHashProxy.new self do
|
14
|
+
@object
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set ivars on object using string" do
|
19
|
+
@proxy['foo'] = 'bar'
|
20
|
+
@object.instance_eval{@foo}.should == 'bar'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set ivars on object using symbol" do
|
24
|
+
@proxy[:foo] = 'bar'
|
25
|
+
@object.instance_eval{@foo}.should == 'bar'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should access object's assigns with a string" do
|
29
|
+
@object.assigns['foo'] = 'bar'
|
30
|
+
@proxy[:foo].should == 'bar'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should access object's assigns with a symbol" do
|
34
|
+
@object.assigns['foo'] = 'bar'
|
35
|
+
@proxy[:foo].should == 'bar'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "iterates through each element like a Hash" do
|
39
|
+
values = {
|
40
|
+
'foo' => 1,
|
41
|
+
'bar' => 2,
|
42
|
+
'baz' => 3
|
43
|
+
}
|
44
|
+
@proxy['foo'] = values['foo']
|
45
|
+
@proxy['bar'] = values['bar']
|
46
|
+
@proxy['baz'] = values['baz']
|
47
|
+
|
48
|
+
@proxy.each do |key, value|
|
49
|
+
key.should == key
|
50
|
+
value.should == values[key]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "deletes the element of passed in key" do
|
55
|
+
@object.assigns['foo'] = 'bar'
|
56
|
+
@proxy.delete('foo').should == 'bar'
|
57
|
+
@proxy['foo'].should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "detects the presence of a key" do
|
61
|
+
@object.assigns['foo'] = 'bar'
|
62
|
+
@proxy.has_key?('foo').should == true
|
63
|
+
@proxy.has_key?('bar').should == false
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Example
|
5
|
+
describe Configuration, :shared => true do
|
6
|
+
before(:each) { @config = Configuration.new }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Configuration, "#use_transactional_fixtures" do
|
10
|
+
it_should_behave_like "Spec::Example::Configuration"
|
11
|
+
|
12
|
+
it "should return Test::Unit::TestCase.use_transactional_fixtures" do
|
13
|
+
@config.use_transactional_fixtures.should == Test::Unit::TestCase.use_transactional_fixtures
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set Test::Unit::TestCase.use_transactional_fixtures to false" do
|
17
|
+
Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
|
18
|
+
example_group.should_receive(:use_transactional_fixtures=).with(false)
|
19
|
+
end
|
20
|
+
@config.use_transactional_fixtures = false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set Test::Unit::TestCase.use_transactional_fixtures to true" do
|
24
|
+
Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
|
25
|
+
example_group.should_receive(:use_transactional_fixtures=).with(true)
|
26
|
+
end
|
27
|
+
@config.use_transactional_fixtures = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Configuration, "#use_instantiated_fixtures" do
|
32
|
+
it_should_behave_like "Spec::Example::Configuration"
|
33
|
+
|
34
|
+
it "should return Test::Unit::TestCase.use_transactional_fixtures" do
|
35
|
+
@config.use_instantiated_fixtures.should == Test::Unit::TestCase.use_instantiated_fixtures
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set Test::Unit::TestCase.use_instantiated_fixtures to false" do
|
39
|
+
Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
|
40
|
+
example_group.should_receive(:use_instantiated_fixtures=).with(false)
|
41
|
+
end
|
42
|
+
@config.use_instantiated_fixtures = false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set Test::Unit::TestCase.use_instantiated_fixtures to true" do
|
46
|
+
Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
|
47
|
+
example_group.should_receive(:use_instantiated_fixtures=).with(true)
|
48
|
+
end
|
49
|
+
@config.use_instantiated_fixtures = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe Configuration, "#fixture_path" do
|
54
|
+
it_should_behave_like "Spec::Example::Configuration"
|
55
|
+
|
56
|
+
it "should default to RAILS_ROOT + '/spec/fixtures'" do
|
57
|
+
@config.fixture_path.should == RAILS_ROOT + '/spec/fixtures'
|
58
|
+
Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
|
59
|
+
example_group.fixture_path.should == RAILS_ROOT + '/spec/fixtures'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set fixture_path" do
|
64
|
+
@config.fixture_path = "/new/path"
|
65
|
+
@config.fixture_path.should == "/new/path"
|
66
|
+
Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
|
67
|
+
example_group.fixture_path.should == "/new/path"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Configuration, "#global_fixtures" do
|
73
|
+
it_should_behave_like "Spec::Example::Configuration"
|
74
|
+
|
75
|
+
it "should set fixtures on TestCase" do
|
76
|
+
Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
|
77
|
+
example_group.should_receive(:fixtures).with(:blah)
|
78
|
+
end
|
79
|
+
@config.global_fixtures = [:blah]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require 'controller_spec_controller'
|
3
|
+
|
4
|
+
describe "a controller spec running in isolation mode", :type => :controller do
|
5
|
+
controller_name :controller_spec
|
6
|
+
|
7
|
+
it "should not care if the template doesn't exist" do
|
8
|
+
get 'some_action'
|
9
|
+
response.should be_success
|
10
|
+
response.should render_template("template/that/does/not/actually/exist")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not care if the template has errors" do
|
14
|
+
get 'action_with_errors_in_template'
|
15
|
+
response.should be_success
|
16
|
+
response.should render_template("action_with_errors_in_template")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "a controller spec running in integration mode", :type => :controller do
|
21
|
+
controller_name :controller_spec
|
22
|
+
integrate_views
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
controller.class.send(:define_method, :rescue_action) { |e| raise e }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should render a template" do
|
29
|
+
get 'action_with_template'
|
30
|
+
response.should be_success
|
31
|
+
response.should have_tag('div', 'This is action_with_template.rhtml')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should choke if the template doesn't exist" do
|
35
|
+
error = defined?(ActionController::MissingTemplate) ? ActionController::MissingTemplate : ActionView::MissingTemplate
|
36
|
+
lambda { get 'some_action' }.should raise_error(error)
|
37
|
+
response.should_not be_success
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should choke if the template has errors" do
|
41
|
+
lambda { get 'action_with_errors_in_template' }.should raise_error(ActionView::TemplateError)
|
42
|
+
response.should_not be_success
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "nested" do
|
46
|
+
it "should render a template" do
|
47
|
+
get 'action_with_template'
|
48
|
+
response.should be_success
|
49
|
+
response.should have_tag('div', 'This is action_with_template.rhtml')
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "with integrate_views turned off" do
|
53
|
+
integrate_views false
|
54
|
+
|
55
|
+
it "should not care if the template doesn't exist" do
|
56
|
+
get 'some_action'
|
57
|
+
response.should be_success
|
58
|
+
response.should render_template("template/that/does/not/actually/exist")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require 'controller_spec_controller'
|
3
|
+
|
4
|
+
['integration', 'isolation'].each do |mode|
|
5
|
+
describe "A controller example running in #{mode} mode", :type => :controller do
|
6
|
+
controller_name :controller_spec
|
7
|
+
integrate_views if mode == 'integration'
|
8
|
+
|
9
|
+
it "should provide controller.session as session" do
|
10
|
+
get 'action_with_template'
|
11
|
+
session.should equal(controller.session)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should provide the same session object before and after the action" do
|
15
|
+
session_before = session
|
16
|
+
get 'action_with_template'
|
17
|
+
session.should equal(session_before)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should keep the same data in the session before and after the action" do
|
21
|
+
session[:foo] = :bar
|
22
|
+
get 'action_with_template'
|
23
|
+
session[:foo].should == :bar
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should ensure controller.session is NOT nil before the action" do
|
27
|
+
controller.session.should_not be_nil
|
28
|
+
get 'action_with_template'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should ensure controller.session is NOT nil after the action" do
|
32
|
+
get 'action_with_template'
|
33
|
+
controller.session.should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow specifying a partial with partial name only" do
|
37
|
+
get 'action_with_partial'
|
38
|
+
response.should render_template("_partial")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should allow specifying a partial with should_receive(:render)" do
|
42
|
+
controller.should_receive(:render).with(:partial => "controller_spec/partial")
|
43
|
+
get 'action_with_partial'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should allow specifying a partial with should_receive(:render) with object" do
|
47
|
+
controller.should_receive(:render).with(:partial => "controller_spec/partial", :object => "something")
|
48
|
+
get 'action_with_partial_with_object', :thing => "something"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should allow specifying a partial with should_receive(:render) with locals" do
|
52
|
+
controller.should_receive(:render).with(:partial => "controller_spec/partial", :locals => {:thing => "something"})
|
53
|
+
get 'action_with_partial_with_locals', :thing => "something"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should yield to render :update" do
|
57
|
+
template = stub("template")
|
58
|
+
controller.should_receive(:render).with(:update).and_yield(template)
|
59
|
+
template.should_receive(:replace).with(:bottom, "replace_me", :partial => "non_existent_partial")
|
60
|
+
get 'action_with_render_update'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should allow a path relative to RAILS_ROOT/app/views/ when specifying a partial" do
|
64
|
+
get 'action_with_partial'
|
65
|
+
response.should render_template("controller_spec/_partial")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should provide access to flash" do
|
69
|
+
get 'action_which_sets_flash'
|
70
|
+
flash[:flash_key].should == "flash value"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should provide access to flash values set after a session reset" do
|
74
|
+
get 'action_setting_flash_after_session_reset'
|
75
|
+
flash[:after_reset].should == "available"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not provide access to flash values set before a session reset" do
|
79
|
+
get 'action_setting_flash_before_session_reset'
|
80
|
+
flash[:before_reset].should_not == "available"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should provide access to session" do
|
84
|
+
session[:session_key] = "session value"
|
85
|
+
lambda do
|
86
|
+
get 'action_which_gets_session', :expected => "session value"
|
87
|
+
end.should_not raise_error
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "handling should_receive(:render)" do
|
91
|
+
it "should warn" do
|
92
|
+
controller.should_receive(:render).with(:template => "controller_spec/action_with_template")
|
93
|
+
get :action_with_template
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "handling should_not_receive(:render)" do
|
98
|
+
it "should warn" do
|
99
|
+
controller.should_not_receive(:render).with(:template => "the/wrong/template")
|
100
|
+
get :action_with_template
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "handling deprecated expect_render" do
|
105
|
+
it "should warn" do
|
106
|
+
Kernel.should_receive(:warn).with(/expect_render is deprecated/)
|
107
|
+
controller.expect_render(:template => "controller_spec/action_with_template")
|
108
|
+
get :action_with_template
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "handling deprecated stub_render" do
|
113
|
+
it "should warn" do
|
114
|
+
Kernel.should_receive(:warn).with(/stub_render is deprecated/)
|
115
|
+
controller.stub_render(:template => "controller_spec/action_with_template")
|
116
|
+
get :action_with_template
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "setting cookies in the request" do
|
121
|
+
|
122
|
+
it "should support a String key" do
|
123
|
+
cookies['cookie_key'] = 'cookie value'
|
124
|
+
get 'action_which_gets_cookie', :expected => "cookie value"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should support a Symbol key" do
|
128
|
+
cookies[:cookie_key] = 'cookie value'
|
129
|
+
get 'action_which_gets_cookie', :expected => "cookie value"
|
130
|
+
end
|
131
|
+
|
132
|
+
if Rails::VERSION::STRING >= "2.0.0"
|
133
|
+
it "should support a Hash value" do
|
134
|
+
cookies[:cookie_key] = {'value' => 'cookie value', 'path' => '/not/default'}
|
135
|
+
get 'action_which_gets_cookie', :expected => {'value' => 'cookie value', 'path' => '/not/default'}
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "reading cookies from the response" do
|
142
|
+
|
143
|
+
it "should support a Symbol key" do
|
144
|
+
get 'action_which_sets_cookie', :value => "cookie value"
|
145
|
+
cookies[:cookie_key].value.should == ["cookie value"]
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should support a String key" do
|
149
|
+
get 'action_which_sets_cookie', :value => "cookie value"
|
150
|
+
cookies['cookie_key'].value.should == ["cookie value"]
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should support custom routes" do
|
156
|
+
route_for(:controller => "custom_route_spec", :action => "custom_route").should == "/custom_route"
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should support existing routes" do
|
160
|
+
route_for(:controller => "controller_spec", :action => "some_action").should == "/controller_spec/some_action"
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should generate params for custom routes" do
|
164
|
+
params_from(:get, '/custom_route').should == {:controller => "custom_route_spec", :action => "custom_route"}
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should generate params for existing routes" do
|
168
|
+
params_from(:get, '/controller_spec/some_action').should == {:controller => "controller_spec", :action => "some_action"}
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should expose instance vars through the assigns hash" do
|
172
|
+
get 'action_setting_the_assigns_hash'
|
173
|
+
assigns[:indirect_assigns_key].should == :indirect_assigns_key_value
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should NOT complain when calling should_receive with arguments other than :render" do
|
177
|
+
controller.should_receive(:anything_besides_render)
|
178
|
+
lambda {
|
179
|
+
controller.rspec_verify
|
180
|
+
}.should raise_error(Exception, /expected :anything_besides_render/)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should not run a skipped before_filter" do
|
184
|
+
lambda {
|
185
|
+
get 'action_with_skipped_before_filter'
|
186
|
+
}.should_not raise_error
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "Given a controller spec for RedirectSpecController running in #{mode} mode", :type => :controller do
|
191
|
+
controller_name :redirect_spec
|
192
|
+
integrate_views if mode == 'integration'
|
193
|
+
|
194
|
+
it "a redirect should ignore the absence of a template" do
|
195
|
+
get 'action_with_redirect_to_somewhere'
|
196
|
+
response.should be_redirect
|
197
|
+
response.redirect_url.should == "http://test.host/redirect_spec/somewhere"
|
198
|
+
response.should redirect_to("http://test.host/redirect_spec/somewhere")
|
199
|
+
end
|
200
|
+
|
201
|
+
it "a call to response.should redirect_to should fail if no redirect" do
|
202
|
+
get 'action_with_no_redirect'
|
203
|
+
lambda {
|
204
|
+
response.redirect?.should be_true
|
205
|
+
}.should fail
|
206
|
+
lambda {
|
207
|
+
response.should redirect_to("http://test.host/redirect_spec/somewhere")
|
208
|
+
}.should fail_with("expected redirect to \"http://test.host/redirect_spec/somewhere\", got no redirect")
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "Given a controller spec running in #{mode} mode" do
|
213
|
+
example_group = describe "A controller spec"
|
214
|
+
# , :type => :controller do
|
215
|
+
# integrate_views if mode == 'integration'
|
216
|
+
it "a spec in a context without controller_name set should fail with a useful warning" do
|
217
|
+
pending("need a new way to deal with examples that should_raise")
|
218
|
+
# ,
|
219
|
+
# :should_raise => [
|
220
|
+
# Spec::Expectations::ExpectationNotMetError,
|
221
|
+
# /You have to declare the controller name in controller specs/
|
222
|
+
# ] do
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
['integration', 'isolation'].each do |mode|
|
229
|
+
describe "A controller example running in #{mode} mode", :type => :controller do
|
230
|
+
controller_name :controller_inheriting_from_application_controller
|
231
|
+
integrate_views if mode == 'integration'
|
232
|
+
|
233
|
+
it "should only have a before filter inherited from ApplicationController run once..." do
|
234
|
+
controller.should_receive(:i_should_only_be_run_once).once
|
235
|
+
get :action_with_inherited_before_filter
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
describe ControllerSpecController, :type => :controller do
|
242
|
+
it "should not require naming the controller if describe is passed a type" do
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe "A controller spec with controller_name set", :type => :controller do
|
247
|
+
controller_name :controller_spec
|
248
|
+
|
249
|
+
describe "nested" do
|
250
|
+
it "should inherit the controller name" do
|
251
|
+
get 'action_with_template'
|
252
|
+
response.should be_success
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
module Spec
|
258
|
+
module Rails
|
259
|
+
module Example
|
260
|
+
describe ControllerExampleGroup do
|
261
|
+
it "should clear its name from the description" do
|
262
|
+
group = describe("foo", :type => :controller) do
|
263
|
+
$nested_group = describe("bar") do
|
264
|
+
end
|
265
|
+
end
|
266
|
+
group.description.to_s.should == "foo"
|
267
|
+
$nested_group.description.to_s.should == "foo bar"
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|