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,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
class CookiesProxyExamplesController < ActionController::Base
|
4
|
+
def index
|
5
|
+
cookies[:key] = cookies[:key]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Spec
|
10
|
+
module Rails
|
11
|
+
module Example
|
12
|
+
describe CookiesProxy, :type => :controller do
|
13
|
+
controller_name :cookies_proxy_examples
|
14
|
+
|
15
|
+
describe "with a String key" do
|
16
|
+
|
17
|
+
it "should accept a String value" do
|
18
|
+
cookies = CookiesProxy.new(self)
|
19
|
+
cookies['key'] = 'value'
|
20
|
+
get :index
|
21
|
+
cookies['key'].should == ['value']
|
22
|
+
end
|
23
|
+
|
24
|
+
if Rails::VERSION::STRING >= "2.0.0"
|
25
|
+
it "should accept a Hash value" do
|
26
|
+
cookies = CookiesProxy.new(self)
|
27
|
+
cookies['key'] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
|
28
|
+
get :index
|
29
|
+
cookies['key'].should == ['value']
|
30
|
+
cookies['key'].value.should == ['value']
|
31
|
+
cookies['key'].expires.should == expiration
|
32
|
+
cookies['key'].path.should == path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "with a Symbol key" do
|
39
|
+
|
40
|
+
it "should accept a String value" do
|
41
|
+
example_cookies = CookiesProxy.new(self)
|
42
|
+
example_cookies[:key] = 'value'
|
43
|
+
get :index
|
44
|
+
example_cookies[:key].should == ['value']
|
45
|
+
end
|
46
|
+
|
47
|
+
if Rails::VERSION::STRING >= "2.0.0"
|
48
|
+
it "should accept a Hash value" do
|
49
|
+
example_cookies = CookiesProxy.new(self)
|
50
|
+
example_cookies[:key] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
|
51
|
+
get :index
|
52
|
+
example_cookies[:key].should == ['value']
|
53
|
+
example_cookies[:key].value.should == ['value']
|
54
|
+
example_cookies[:key].expires.should == expiration
|
55
|
+
example_cookies[:key].path.should == path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#delete" do
|
62
|
+
it "should delete from the response cookies" do
|
63
|
+
example_cookies = CookiesProxy.new(self)
|
64
|
+
response_cookies = mock('cookies')
|
65
|
+
response.should_receive(:cookies).and_return(response_cookies)
|
66
|
+
response_cookies.should_receive(:delete).with('key')
|
67
|
+
example_cookies.delete :key
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Example
|
5
|
+
describe ExampleGroupFactory do
|
6
|
+
it "should return a ModelExampleGroup when given :type => :model" do
|
7
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
8
|
+
"name", :type => :model
|
9
|
+
) {}
|
10
|
+
example_group.superclass.should == Spec::Rails::Example::ModelExampleGroup
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return a ModelExampleGroup when given :spec_path => '/blah/spec/models/'" do
|
14
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
15
|
+
"name", :spec_path => '/blah/spec/models/blah.rb'
|
16
|
+
) {}
|
17
|
+
example_group.superclass.should == Spec::Rails::Example::ModelExampleGroup
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return a ModelExampleGroup when given :spec_path => '\\blah\\spec\\models\\' (windows format)" do
|
21
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
22
|
+
"name", :spec_path => '\\blah\\spec\\models\\blah.rb'
|
23
|
+
) {}
|
24
|
+
example_group.superclass.should == Spec::Rails::Example::ModelExampleGroup
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return a RailsExampleGroup when given :spec_path => '/blah/spec/foo/' (anything other than controllers, views and helpers)" do
|
28
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
29
|
+
"name", :spec_path => '/blah/spec/foo/blah.rb'
|
30
|
+
) {}
|
31
|
+
example_group.superclass.should == Spec::Rails::Example::RailsExampleGroup
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return a RailsExampleGroup when given :spec_path => '\\blah\\spec\\foo\\' (windows format) (anything other than controllers, views and helpers)" do
|
35
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
36
|
+
"name", :spec_path => '\\blah\\spec\\foo\\blah.rb'
|
37
|
+
) {}
|
38
|
+
example_group.superclass.should == Spec::Rails::Example::RailsExampleGroup
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return a ViewExampleGroup when given :type => :model" do
|
42
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
43
|
+
"name", :type => :view
|
44
|
+
) {}
|
45
|
+
example_group.superclass.should == Spec::Rails::Example::ViewExampleGroup
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return a ViewExampleGroup when given :spec_path => '/blah/spec/views/'" do
|
49
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
50
|
+
"name", :spec_path => '/blah/spec/views/blah.rb'
|
51
|
+
) {}
|
52
|
+
example_group.superclass.should == Spec::Rails::Example::ViewExampleGroup
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return a ModelExampleGroup when given :spec_path => '\\blah\\spec\\views\\' (windows format)" do
|
56
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
57
|
+
"name", :spec_path => '\\blah\\spec\\views\\blah.rb'
|
58
|
+
) {}
|
59
|
+
example_group.superclass.should == Spec::Rails::Example::ViewExampleGroup
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return a HelperExampleGroup when given :type => :helper" do
|
63
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
64
|
+
"name", :type => :helper
|
65
|
+
) {}
|
66
|
+
example_group.superclass.should == Spec::Rails::Example::HelperExampleGroup
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return a HelperExampleGroup when given :spec_path => '/blah/spec/helpers/'" do
|
70
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
71
|
+
"name", :spec_path => '/blah/spec/helpers/blah.rb'
|
72
|
+
) {}
|
73
|
+
example_group.superclass.should == Spec::Rails::Example::HelperExampleGroup
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return a ModelExampleGroup when given :spec_path => '\\blah\\spec\\helpers\\' (windows format)" do
|
77
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
78
|
+
"name", :spec_path => '\\blah\\spec\\helpers\\blah.rb'
|
79
|
+
) {}
|
80
|
+
example_group.superclass.should == Spec::Rails::Example::HelperExampleGroup
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return a ControllerExampleGroup when given :type => :controller" do
|
84
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
85
|
+
"name", :type => :controller
|
86
|
+
) {}
|
87
|
+
example_group.superclass.should == Spec::Rails::Example::ControllerExampleGroup
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return a ControllerExampleGroup when given :spec_path => '/blah/spec/controllers/'" do
|
91
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
92
|
+
"name", :spec_path => '/blah/spec/controllers/blah.rb'
|
93
|
+
) {}
|
94
|
+
example_group.superclass.should == Spec::Rails::Example::ControllerExampleGroup
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return a ModelExampleGroup when given :spec_path => '\\blah\\spec\\controllers\\' (windows format)" do
|
98
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
99
|
+
"name", :spec_path => '\\blah\\spec\\controllers\\blah.rb'
|
100
|
+
) {}
|
101
|
+
example_group.superclass.should == Spec::Rails::Example::ControllerExampleGroup
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should favor the :type over the :spec_path" do
|
105
|
+
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
|
106
|
+
"name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller
|
107
|
+
) {}
|
108
|
+
example_group.superclass.should == Spec::Rails::Example::ControllerExampleGroup
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
Spec::Runner.configuration.global_fixtures = :people
|
3
|
+
|
4
|
+
describe ExplicitHelper, :type => :helper do
|
5
|
+
include ExplicitHelper
|
6
|
+
|
7
|
+
it "should not require naming the helper if describe is passed a type" do
|
8
|
+
method_in_explicit_helper.should match(/text from a method/)
|
9
|
+
helper.method_in_explicit_helper.should match(/text from a method/)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Spec
|
14
|
+
module Rails
|
15
|
+
module Example
|
16
|
+
describe HelperExampleGroup, :type => :helper do
|
17
|
+
helper_name :explicit
|
18
|
+
|
19
|
+
it "DEPRECATED should have direct access to methods defined in helpers" do
|
20
|
+
method_in_explicit_helper.should =~ /text from a method/
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should expose the helper with the #helper method" do
|
24
|
+
helper.method_in_explicit_helper.should =~ /text from a method/
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have access to named routes" do
|
28
|
+
rspec_on_rails_specs_url.should == "http://test.host/rspec_on_rails_specs"
|
29
|
+
rspec_on_rails_specs_path.should == "/rspec_on_rails_specs"
|
30
|
+
|
31
|
+
helper.named_url.should == "http://test.host/rspec_on_rails_specs"
|
32
|
+
helper.named_path.should == "/rspec_on_rails_specs"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fail if the helper method deson't exist" do
|
36
|
+
lambda { non_existent_helper_method }.should raise_error(NameError)
|
37
|
+
lambda { helper.non_existent_helper_method }.should raise_error(NameError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have access to session" do
|
41
|
+
session[:foo] = 'bar'
|
42
|
+
session_foo.should == 'bar'
|
43
|
+
helper.session_foo.should == 'bar'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should have access to params" do
|
47
|
+
params[:foo] = 'bar'
|
48
|
+
params_foo.should == 'bar'
|
49
|
+
helper.params_foo.should == 'bar'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have access to request" do
|
53
|
+
request.stub!(:thing).and_return('bar')
|
54
|
+
request_thing.should == 'bar'
|
55
|
+
helper.request_thing.should == 'bar'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have access to flash" do
|
59
|
+
flash[:thing] = 'camera'
|
60
|
+
flash_thing.should == 'camera'
|
61
|
+
helper.flash_thing.should == 'camera'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe HelperExampleGroup, "#eval_erb", :type => :helper do
|
66
|
+
helper_name :explicit
|
67
|
+
|
68
|
+
it "should support methods that accept blocks" do
|
69
|
+
eval_erb("<% prepend 'foo' do %>bar<% end %>").should == "foobar"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe HelperExampleGroup, ".fixtures", :type => :helper do
|
74
|
+
helper_name :explicit
|
75
|
+
fixtures :animals
|
76
|
+
|
77
|
+
it "should load fixtures" do
|
78
|
+
pig = animals(:pig)
|
79
|
+
pig.class.should == Animal
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should load global fixtures" do
|
83
|
+
lachie = people(:lachie)
|
84
|
+
lachie.class.should == Person
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "methods from standard helpers", :type => :helper do
|
89
|
+
helper_name :explicit
|
90
|
+
it "should be exposed to the helper" do
|
91
|
+
helper.link_to("Foo","http://bar").should have_tag("a")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe HelperExampleGroup, "included modules", :type => :helper do
|
96
|
+
helpers = [
|
97
|
+
ActionView::Helpers::ActiveRecordHelper,
|
98
|
+
ActionView::Helpers::AssetTagHelper,
|
99
|
+
ActionView::Helpers::BenchmarkHelper,
|
100
|
+
ActionView::Helpers::CacheHelper,
|
101
|
+
ActionView::Helpers::CaptureHelper,
|
102
|
+
ActionView::Helpers::DateHelper,
|
103
|
+
ActionView::Helpers::DebugHelper,
|
104
|
+
ActionView::Helpers::FormHelper,
|
105
|
+
ActionView::Helpers::FormOptionsHelper,
|
106
|
+
ActionView::Helpers::FormTagHelper,
|
107
|
+
ActionView::Helpers::JavaScriptHelper,
|
108
|
+
ActionView::Helpers::NumberHelper,
|
109
|
+
ActionView::Helpers::PrototypeHelper,
|
110
|
+
ActionView::Helpers::ScriptaculousHelper,
|
111
|
+
ActionView::Helpers::TagHelper,
|
112
|
+
ActionView::Helpers::TextHelper,
|
113
|
+
ActionView::Helpers::UrlHelper
|
114
|
+
]
|
115
|
+
helpers << ActionView::Helpers::PaginationHelper rescue nil #removed for 2.0
|
116
|
+
helpers << ActionView::Helpers::JavaScriptMacrosHelper rescue nil #removed for 2.0
|
117
|
+
helpers.each do |helper_module|
|
118
|
+
it "should include #{helper_module}" do
|
119
|
+
self.class.ancestors.should include(helper_module)
|
120
|
+
helper.class.ancestors.should include(helper_module)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# TODO: BT - Helper Examples should proxy method_missing to a Rails View instance.
|
126
|
+
# When that is done, remove this method
|
127
|
+
describe HelperExampleGroup, "#protect_against_forgery?", :type => :helper do
|
128
|
+
it "should return false" do
|
129
|
+
protect_against_forgery?.should be_false
|
130
|
+
helper.protect_against_forgery?.should be_false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
module Bug11223
|
138
|
+
# see http://rubyforge.org/tracker/index.php?func=detail&aid=11223&group_id=797&atid=3149
|
139
|
+
describe 'Accessing flash from helper spec', :type => :helper do
|
140
|
+
it 'should not raise an error' do
|
141
|
+
lambda { flash['test'] }.should_not raise_error
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
module Spec
|
147
|
+
module Rails
|
148
|
+
module Example
|
149
|
+
describe HelperExampleGroup do
|
150
|
+
it "should clear its name from the description" do
|
151
|
+
group = describe("foo", :type => :helper) do
|
152
|
+
$nested_group = describe("bar") do
|
153
|
+
end
|
154
|
+
end
|
155
|
+
group.description.to_s.should == "foo"
|
156
|
+
$nested_group.description.to_s.should == "foo bar"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Rails
|
5
|
+
module Example
|
6
|
+
describe ModelExampleGroup do
|
7
|
+
it "should clear its name from the description" do
|
8
|
+
group = describe("foo", :type => :model) do
|
9
|
+
$nested_group = describe("bar") do
|
10
|
+
end
|
11
|
+
end
|
12
|
+
group.description.to_s.should == "foo"
|
13
|
+
$nested_group.description.to_s.should == "foo bar"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe "A shared view example_group", :shared => true do
|
4
|
+
it "should have some tag with some text" do
|
5
|
+
response.should have_tag('div', 'This is text from a method in the ViewSpecHelper')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "A view example_group", :type => :view do
|
10
|
+
it_should_behave_like "A shared view example_group"
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
render "view_spec/implicit_helper"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe "assert_equal", :shared => true do
|
4
|
+
it "like assert_equal" do
|
5
|
+
assert_equal 1, 1
|
6
|
+
lambda {
|
7
|
+
assert_equal 1, 2
|
8
|
+
}.should raise_error(Test::Unit::AssertionFailedError)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "A model spec should be able to access 'test/unit' assertions", :type => :model do
|
13
|
+
it_should_behave_like "assert_equal"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "A view spec should be able to access 'test/unit' assertions", :type => :view do
|
17
|
+
it_should_behave_like "assert_equal"
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "A helper spec should be able to access 'test/unit' assertions", :type => :helper do
|
21
|
+
it_should_behave_like "assert_equal"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "A controller spec with integrated views should be able to access 'test/unit' assertions", :type => :controller do
|
25
|
+
controller_name :controller_spec
|
26
|
+
integrate_views
|
27
|
+
it_should_behave_like "assert_equal"
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "A controller spec should be able to access 'test/unit' assertions", :type => :controller do
|
31
|
+
controller_name :controller_spec
|
32
|
+
it_should_behave_like "assert_equal"
|
33
|
+
end
|
@@ -0,0 +1,280 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe "A template with an implicit helper", :type => :view do
|
4
|
+
before(:each) do
|
5
|
+
render "view_spec/implicit_helper"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should include the helper" do
|
9
|
+
response.should have_tag('div', :content => "This is text from a method in the ViewSpecHelper")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should include the application helper" do
|
13
|
+
response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have access to named routes" do
|
17
|
+
rspec_on_rails_specs_url.should == "http://test.host/rspec_on_rails_specs"
|
18
|
+
rspec_on_rails_specs_path.should == "/rspec_on_rails_specs"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "A template requiring an explicit helper", :type => :view do
|
23
|
+
before(:each) do
|
24
|
+
render "view_spec/explicit_helper", :helper => 'explicit'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should include the helper if specified" do
|
28
|
+
response.should have_tag('div', :content => "This is text from a method in the ExplicitHelper")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should include the application helper" do
|
32
|
+
response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "A template requiring multiple explicit helpers", :type => :view do
|
37
|
+
before(:each) do
|
38
|
+
render "view_spec/multiple_helpers", :helpers => ['explicit', 'more_explicit']
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should include all specified helpers" do
|
42
|
+
response.should have_tag('div', :content => "This is text from a method in the ExplicitHelper")
|
43
|
+
response.should have_tag('div', :content => "This is text from a method in the MoreExplicitHelper")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should include the application helper" do
|
47
|
+
response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Message Expectations on helper methods", :type => :view do
|
52
|
+
it "should work" do
|
53
|
+
template.should_receive(:method_in_plugin_application_helper).and_return('alternate message 1')
|
54
|
+
render "view_spec/implicit_helper"
|
55
|
+
response.body.should =~ /alternate message 1/
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should work twice" do
|
59
|
+
template.should_receive(:method_in_plugin_application_helper).and_return('alternate message 2')
|
60
|
+
render "view_spec/implicit_helper"
|
61
|
+
response.body.should =~ /alternate message 2/
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "A template that includes a partial", :type => :view do
|
66
|
+
def render!
|
67
|
+
render "view_spec/template_with_partial"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should render the enclosing template" do
|
71
|
+
render!
|
72
|
+
response.should have_tag('div', "method_in_partial in ViewSpecHelper")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should render the partial" do
|
76
|
+
render!
|
77
|
+
response.should have_tag('div', "method_in_template_with_partial in ViewSpecHelper")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should include the application helper" do
|
81
|
+
render!
|
82
|
+
response.should have_tag('div', "This is text from a method in the ApplicationHelper")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should pass should_receive(:render) with the right partial" do
|
86
|
+
template.should_receive(:render).with(:partial => 'partial')
|
87
|
+
render!
|
88
|
+
template.verify_rendered
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should fail should_receive(:render) with the wrong partial" do
|
92
|
+
template.should_receive(:render).with(:partial => 'non_existent')
|
93
|
+
render!
|
94
|
+
begin
|
95
|
+
template.verify_rendered
|
96
|
+
rescue Spec::Mocks::MockExpectationError => e
|
97
|
+
ensure
|
98
|
+
e.backtrace.find{|line| line =~ /view_spec_spec\.rb\:92/}.should_not be_nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should pass should_receive(:render) when a partial is expected twice and happens twice" do
|
103
|
+
template.should_receive(:render).with(:partial => 'partial_used_twice').twice
|
104
|
+
render!
|
105
|
+
template.verify_rendered
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should pass should_receive(:render) when a partial is expected once and happens twice" do
|
109
|
+
template.should_receive(:render).with(:partial => 'partial_used_twice')
|
110
|
+
render!
|
111
|
+
begin
|
112
|
+
template.verify_rendered
|
113
|
+
rescue Spec::Mocks::MockExpectationError => e
|
114
|
+
ensure
|
115
|
+
e.backtrace.find{|line| line =~ /view_spec_spec\.rb\:109/}.should_not be_nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should fail should_receive(:render) with the right partial but wrong options" do
|
120
|
+
template.should_receive(:render).with(:partial => 'partial', :locals => {:thing => Object.new})
|
121
|
+
render!
|
122
|
+
lambda {template.verify_rendered}.should raise_error(Spec::Mocks::MockExpectationError)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "A partial that includes a partial", :type => :view do
|
127
|
+
it "should support should_receive(:render) with nested partial" do
|
128
|
+
obj = Object.new
|
129
|
+
template.should_receive(:render).with(:partial => 'partial', :object => obj)
|
130
|
+
render :partial => "view_spec/partial_with_sub_partial", :locals => { :partial => obj }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "A view that includes a partial using :collection and :spacer_template", :type => :view do
|
135
|
+
it "should render the partial w/ spacer_tamplate" do
|
136
|
+
render "view_spec/template_with_partial_using_collection"
|
137
|
+
response.should have_tag('div',/method_in_partial/)
|
138
|
+
response.should have_tag('div',/ApplicationHelper/)
|
139
|
+
response.should have_tag('div',/ViewSpecHelper/)
|
140
|
+
response.should have_tag('hr#spacer')
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should render the partial" do
|
144
|
+
template.should_receive(:render).with(:partial => 'partial',
|
145
|
+
:collection => ['Alice', 'Bob'],
|
146
|
+
:spacer_template => 'spacer')
|
147
|
+
render "view_spec/template_with_partial_using_collection"
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
if Rails::VERSION::MAJOR >= 2
|
153
|
+
describe "A view that includes a partial using an array as partial_path", :type => :view do
|
154
|
+
before(:each) do
|
155
|
+
renderable_object = Object.new
|
156
|
+
renderable_object.stub!(:name).and_return("Renderable Object")
|
157
|
+
assigns[:array] = [renderable_object]
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should render the array passed through to render_partial without modification" do
|
161
|
+
render "view_spec/template_with_partial_with_array"
|
162
|
+
response.body.should match(/^Renderable Object$/)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "Different types of renders (not :template)", :type => :view do
|
168
|
+
it "should render partial with local" do
|
169
|
+
render :partial => "view_spec/partial_with_local_variable", :locals => {:x => "Ender"}
|
170
|
+
response.should have_tag('div', :content => "Ender")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "A view", :type => :view do
|
175
|
+
before(:each) do
|
176
|
+
session[:key] = "session"
|
177
|
+
params[:key] = "params"
|
178
|
+
flash[:key] = "flash"
|
179
|
+
render "view_spec/accessor"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should have access to session data" do
|
183
|
+
response.should have_tag("div#session", "session")
|
184
|
+
end
|
185
|
+
|
186
|
+
specify "should have access to params data" do
|
187
|
+
response.should have_tag("div#params", "params")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should have access to flash data" do
|
191
|
+
response.should have_tag("div#flash", "flash")
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should have a controller param" do
|
195
|
+
response.should have_tag("div#controller", "view_spec")
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should have an action param" do
|
199
|
+
response.should have_tag("div#action", "accessor")
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "A view with a form_tag", :type => :view do
|
204
|
+
it "should render the right action" do
|
205
|
+
render "view_spec/entry_form"
|
206
|
+
response.should have_tag("form[action=?]","/view_spec/entry_form")
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "An instantiated ViewExampleGroupController", :type => :view do
|
211
|
+
before do
|
212
|
+
render "view_spec/foo/show"
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should return the name of the real controller that it replaces" do
|
216
|
+
@controller.controller_name.should == 'foo'
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should return the path of the real controller that it replaces" do
|
220
|
+
@controller.controller_path.should == 'view_spec/foo'
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "a block helper", :type => :view do
|
225
|
+
it "should not yield when not told to in the example" do
|
226
|
+
template.should_receive(:if_allowed)
|
227
|
+
render "view_spec/block_helper"
|
228
|
+
response.should_not have_tag("div","block helper was rendered")
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should yield when told to in the example" do
|
232
|
+
template.should_receive(:if_allowed).and_yield
|
233
|
+
render "view_spec/block_helper"
|
234
|
+
response.should have_tag("div","block helper was rendered")
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "render :inline => ...", :type => :view do
|
239
|
+
it "should render ERB right in the spec" do
|
240
|
+
render :inline => %|<%= text_field_tag('field_name', 'Value') %>|
|
241
|
+
response.should have_tag("input[type=?][name=?][value=?]","text","field_name","Value")
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
module Spec
|
246
|
+
module Rails
|
247
|
+
module Example
|
248
|
+
describe ViewExampleGroup do
|
249
|
+
it "should clear its name from the description" do
|
250
|
+
group = describe("foo", :type => :view) do
|
251
|
+
$nested_group = describe("bar") do
|
252
|
+
end
|
253
|
+
end
|
254
|
+
group.description.to_s.should == "foo"
|
255
|
+
$nested_group.description.to_s.should == "foo bar"
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should clear ActionView::Base.base_view_path on teardown" do
|
259
|
+
group = describe("base_view_path_cleared flag", :type => :view) {}
|
260
|
+
example = group.it{}
|
261
|
+
|
262
|
+
ActionView::Base.should_receive(:base_view_path=).with(nil)
|
263
|
+
group.run_after_each(example)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe "bug http://rspec.lighthouseapp.com/projects/5645/tickets/510", :type => :view do
|
271
|
+
describe "a view example with should_not_receive" do
|
272
|
+
it "should render the view" do
|
273
|
+
obj = mock('model')
|
274
|
+
obj.should_receive(:render_partial?).and_return false
|
275
|
+
assigns[:obj] = obj
|
276
|
+
template.should_not_receive(:render).with(:partial => 'some_partial')
|
277
|
+
render "view_spec/should_not_receive"
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|