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,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe "should change" do
|
4
|
+
describe "handling association proxies" do
|
5
|
+
it "should match expected collection with proxied collection" do
|
6
|
+
person = Person.create!(:name => 'David')
|
7
|
+
koala = person.animals.create!(:name => 'Koala')
|
8
|
+
zebra = person.animals.create!(:name => 'Zebra')
|
9
|
+
|
10
|
+
lambda {
|
11
|
+
person.animals.delete(koala)
|
12
|
+
}.should change{person.animals}.to([zebra])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/ar_classes'
|
3
|
+
|
4
|
+
describe "mock_model" do
|
5
|
+
describe "responding to interrogation" do
|
6
|
+
before(:each) do
|
7
|
+
@model = mock_model(SubMockableModel)
|
8
|
+
end
|
9
|
+
it "should say it is_a? if it is" do
|
10
|
+
@model.is_a?(SubMockableModel).should be(true)
|
11
|
+
end
|
12
|
+
it "should say it is_a? if it's ancestor is" do
|
13
|
+
@model.is_a?(MockableModel).should be(true)
|
14
|
+
end
|
15
|
+
it "should say it is kind_of? if it is" do
|
16
|
+
@model.kind_of?(SubMockableModel).should be(true)
|
17
|
+
end
|
18
|
+
it "should say it is kind_of? if it's ancestor is" do
|
19
|
+
@model.kind_of?(MockableModel).should be(true)
|
20
|
+
end
|
21
|
+
it "should say it is instance_of? if it is" do
|
22
|
+
@model.instance_of?(SubMockableModel).should be(true)
|
23
|
+
end
|
24
|
+
it "should not say it instance_of? if it isn't, even if it's ancestor is" do
|
25
|
+
@model.instance_of?(MockableModel).should be(false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with params" do
|
30
|
+
it "should not mutate its parameters" do
|
31
|
+
params = {:a => 'b'}
|
32
|
+
model = mock_model(MockableModel, params)
|
33
|
+
params.should == {:a => 'b'}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with #id stubbed", :type => :view do
|
38
|
+
before(:each) do
|
39
|
+
@model = mock_model(MockableModel, :id => 1)
|
40
|
+
end
|
41
|
+
it "should be named using the stubbed id value" do
|
42
|
+
@model.instance_variable_get(:@name).should == "MockableModel_1"
|
43
|
+
end
|
44
|
+
it "should return string of id value for to_param" do
|
45
|
+
@model.to_param.should == "1"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "as association", :type => :view do
|
50
|
+
before(:each) do
|
51
|
+
@real = AssociatedModel.create!
|
52
|
+
@mock_model = mock_model(MockableModel)
|
53
|
+
@real.mockable_model = @mock_model
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should pass associated_model == mock" do
|
57
|
+
@mock_model.should == @real.mockable_model
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should pass mock == associated_model" do
|
61
|
+
@real.mockable_model.should == @mock_model
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "with :null_object => true", :type => :view do
|
66
|
+
before(:each) do
|
67
|
+
@model = mock_model(MockableModel, :null_object => true, :mocked_method => "mocked")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should be able to mock methods" do
|
71
|
+
@model.mocked_method.should == "mocked"
|
72
|
+
end
|
73
|
+
it "should return itself to unmocked methods" do
|
74
|
+
@model.unmocked_method.should equal(@model)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#as_null_object", :type => :view do
|
79
|
+
before(:each) do
|
80
|
+
@model = mock_model(MockableModel, :mocked_method => "mocked").as_null_object
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should be able to mock methods" do
|
84
|
+
@model.mocked_method.should == "mocked"
|
85
|
+
end
|
86
|
+
it "should return itself to unmocked methods" do
|
87
|
+
@model.unmocked_method.should equal(@model)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#as_new_record" do
|
92
|
+
it "should say it is a new record" do
|
93
|
+
mock_model(MockableModel).as_new_record.should be_new_record
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should have a nil id" do
|
97
|
+
mock_model(MockableModel).as_new_record.id.should be(nil)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return nil for #to_param" do
|
101
|
+
mock_model(MockableModel).as_new_record.to_param.should be(nil)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/ar_classes'
|
3
|
+
|
4
|
+
describe "stub_model" do
|
5
|
+
describe "defaults" do
|
6
|
+
it "should have an id" do
|
7
|
+
stub_model(MockableModel).id.should be > 0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should say it is not a new record" do
|
11
|
+
stub_model(MockableModel).should_not be_new_record
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should accept a stub id" do
|
16
|
+
stub_model(MockableModel, :id => 37).id.should == 37
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should say it is a new record when id is set to nil" do
|
20
|
+
stub_model(MockableModel, :id => nil).should be_new_record
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should accept any arbitrary stub" do
|
24
|
+
stub_model(MockableModel, :foo => "bar").foo.should == "bar"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should accept a stub for save" do
|
28
|
+
stub_model(MockableModel, :save => false).save.should be(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#as_new_record" do
|
32
|
+
it "should say it is a new record" do
|
33
|
+
stub_model(MockableModel).as_new_record.should be_new_record
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have a nil id" do
|
37
|
+
stub_model(MockableModel).as_new_record.id.should be(nil)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise when hitting the db" do
|
42
|
+
lambda do
|
43
|
+
model = stub_model(MockableModel, :changed => true, :attributes_with_quotes => {'this' => 'that'})
|
44
|
+
model.save
|
45
|
+
end.should raise_error(Spec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should increment the id" do
|
49
|
+
first = stub_model(MockableModel)
|
50
|
+
second = stub_model(MockableModel)
|
51
|
+
second.id.should == (first.id + 1)
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "as association" do
|
55
|
+
before(:each) do
|
56
|
+
@real = AssociatedModel.create!
|
57
|
+
@stub_model = stub_model(MockableModel)
|
58
|
+
@real.mockable_model = @stub_model
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should pass associated_model == mock" do
|
62
|
+
@stub_model.should == @real.mockable_model
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should pass mock == associated_model" do
|
66
|
+
@real.mockable_model.should == @stub_model
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "with a block" do
|
71
|
+
it "should yield the model" do
|
72
|
+
model = stub_model(MockableModel) do |block_arg|
|
73
|
+
@block_arg = block_arg
|
74
|
+
end
|
75
|
+
model.should be(@block_arg)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
#
|
3
|
+
# describe "script/spec_server file", :shared => true do
|
4
|
+
# attr_accessor :tmbundle_install_directory
|
5
|
+
# attr_reader :animals_yml_path, :original_animals_content
|
6
|
+
#
|
7
|
+
# before do
|
8
|
+
# @animals_yml_path = File.expand_path("#{RAILS_ROOT}/spec/fixtures/animals.yml")
|
9
|
+
# @original_animals_content = File.read(animals_yml_path)
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# after do
|
13
|
+
# File.open(animals_yml_path, "w") do |f|
|
14
|
+
# f.write original_animals_content
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# after(:each) do
|
19
|
+
# system "lsof -i tcp:8989 | sed /COMMAND/d | awk '{print $2}' | xargs kill"
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# it "runs a spec" do
|
23
|
+
# dir = File.dirname(__FILE__)
|
24
|
+
# output = ""
|
25
|
+
# Timeout.timeout(10) do
|
26
|
+
# loop do
|
27
|
+
# output = `#{RAILS_ROOT}/script/spec #{dir}/sample_spec.rb --drb 2>&1`
|
28
|
+
# break unless output.include?("No server is running")
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# if $?.exitstatus != 0 || output !~ /0 failures/
|
33
|
+
# flunk "command 'script/spec spec/sample_spec' failed\n#{output}"
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# fixtures = YAML.load(@original_animals_content)
|
37
|
+
# fixtures['pig']['name'] = "Piggy"
|
38
|
+
#
|
39
|
+
# File.open(animals_yml_path, "w") do |f|
|
40
|
+
# f.write YAML.dump(fixtures)
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# Timeout.timeout(10) do
|
44
|
+
# loop do
|
45
|
+
# output = `#{RAILS_ROOT}/script/spec #{dir}/sample_modified_fixture.rb --drb 2>&1`
|
46
|
+
# break unless output.include?("No server is running")
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# if $?.exitstatus != 0 || output !~ /0 failures/
|
51
|
+
# flunk "command 'script/spec spec/sample_modified_fixture' failed\n#{output}"
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def start_spec_server
|
56
|
+
# dir = File.dirname(__FILE__)
|
57
|
+
# Thread.start do
|
58
|
+
# system "cd #{RAILS_ROOT}; script/spec_server"
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# file_content = ""
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# describe "script/spec_server file without TextMate bundle" do
|
66
|
+
# it_should_behave_like "script/spec_server file"
|
67
|
+
# before(:each) do
|
68
|
+
# start_spec_server
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# describe "script/spec_server file with TextMate bundle" do
|
73
|
+
# it_should_behave_like "script/spec_server file"
|
74
|
+
# before(:each) do
|
75
|
+
# dir = File.dirname(__FILE__)
|
76
|
+
# @tmbundle_install_directory = File.expand_path("#{Dir.tmpdir}/Library/Application Support/TextMate/Bundles")
|
77
|
+
# @bundle_name = "RSpec.tmbundle"
|
78
|
+
# FileUtils.mkdir_p(tmbundle_install_directory)
|
79
|
+
# bundle_dir = File.expand_path("#{dir}/../../../../../../#{@bundle_name}")
|
80
|
+
# File.directory?(bundle_dir).should be_true
|
81
|
+
# unless system(%Q|ln -s #{bundle_dir} "#{tmbundle_install_directory}"|)
|
82
|
+
# raise "Creating link to Textmate Bundle"
|
83
|
+
# end
|
84
|
+
# start_spec_server
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# after(:each) do
|
88
|
+
# bundle_file_to_remove = "#{tmbundle_install_directory}/#{@bundle_name}"
|
89
|
+
# if bundle_file_to_remove == "/"
|
90
|
+
# raise "bundle file path resolved to '/' - could not call rm"
|
91
|
+
# end
|
92
|
+
# unless system(%Q|rm "#{bundle_file_to_remove}"|)
|
93
|
+
# raise "Removing Textmate bundle link failed"
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
# end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "script/spec file" do
|
4
|
+
it "should run a spec" do
|
5
|
+
dir = File.dirname(__FILE__)
|
6
|
+
output = `#{RAILS_ROOT}/script/spec #{dir}/sample_spec.rb`
|
7
|
+
unless $?.exitstatus == 0
|
8
|
+
flunk "command 'script/spec spec/sample_spec' failed\n#{output}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/rails_suite.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(File.expand_path("#{dir}/../rspec/lib"))
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("#{dir}/../spec_resources/controllers"))
|
4
|
+
$LOAD_PATH.unshift(File.expand_path("#{dir}/../spec_resources/helpers"))
|
5
|
+
require File.expand_path("#{dir}/../../../../spec/spec_helper")
|
6
|
+
require File.expand_path("#{dir}/../spec_resources/controllers/render_spec_controller")
|
7
|
+
require File.expand_path("#{dir}/../spec_resources/controllers/rjs_spec_controller")
|
8
|
+
require File.expand_path("#{dir}/../spec_resources/controllers/redirect_spec_controller")
|
9
|
+
require File.expand_path("#{dir}/../spec_resources/controllers/action_view_base_spec_controller")
|
10
|
+
require File.expand_path("#{dir}/../spec_resources/helpers/explicit_helper")
|
11
|
+
require File.expand_path("#{dir}/../spec_resources/helpers/more_explicit_helper")
|
12
|
+
require File.expand_path("#{dir}/../spec_resources/helpers/view_spec_helper")
|
13
|
+
require File.expand_path("#{dir}/../spec_resources/helpers/plugin_application_helper")
|
14
|
+
|
15
|
+
extra_controller_paths = File.expand_path("#{dir}/../spec_resources/controllers")
|
16
|
+
|
17
|
+
unless ActionController::Routing.controller_paths.include?(extra_controller_paths)
|
18
|
+
ActionController::Routing.instance_eval {@possible_controllers = nil}
|
19
|
+
ActionController::Routing.controller_paths << extra_controller_paths
|
20
|
+
end
|
21
|
+
|
22
|
+
module Spec
|
23
|
+
module Rails
|
24
|
+
module Example
|
25
|
+
class ViewExampleGroupController
|
26
|
+
set_view_path File.join(File.dirname(__FILE__), "..", "spec_resources", "views")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def fail()
|
33
|
+
raise_error(Spec::Expectations::ExpectationNotMetError)
|
34
|
+
end
|
35
|
+
|
36
|
+
def fail_with(message)
|
37
|
+
raise_error(Spec::Expectations::ExpectationNotMetError,message)
|
38
|
+
end
|
39
|
+
|
40
|
+
class Proc
|
41
|
+
def should_pass
|
42
|
+
lambda { self.call }.should_not raise_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Spec::Runner.configure do |config|
|
47
|
+
config.before(:each, :type => :controller) do
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
ActionController::Routing::Routes.draw do |map|
|
53
|
+
map.resources :rspec_on_rails_specs
|
54
|
+
map.connect 'custom_route', :controller => 'custom_route_spec', :action => 'custom_route'
|
55
|
+
map.connect ":controller/:action/:id"
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class ControllerSpecController < ActionController::Base
|
2
|
+
before_filter :raise_error, :only => :action_with_skipped_before_filter
|
3
|
+
|
4
|
+
def raise_error
|
5
|
+
raise "from a before filter"
|
6
|
+
end
|
7
|
+
|
8
|
+
skip_before_filter :raise_error
|
9
|
+
|
10
|
+
if ['edge','2.0.0'].include?(ENV['RSPEC_RAILS_VERSION'])
|
11
|
+
set_view_path [File.join(File.dirname(__FILE__), "..", "views")]
|
12
|
+
else
|
13
|
+
set_view_path File.join(File.dirname(__FILE__), "..", "views")
|
14
|
+
end
|
15
|
+
|
16
|
+
def some_action
|
17
|
+
render :template => "template/that/does/not/actually/exist"
|
18
|
+
end
|
19
|
+
|
20
|
+
def action_with_template
|
21
|
+
render :template => "controller_spec/action_with_template"
|
22
|
+
end
|
23
|
+
|
24
|
+
def action_which_sets_flash
|
25
|
+
flash[:flash_key] = "flash value"
|
26
|
+
render :text => ""
|
27
|
+
end
|
28
|
+
|
29
|
+
def action_which_gets_session
|
30
|
+
raise "expected #{params[:session_key].inspect}\ngot #{session[:session_key].inspect}" unless (session[:session_key] == params[:expected])
|
31
|
+
render :text => ""
|
32
|
+
end
|
33
|
+
|
34
|
+
def action_which_sets_session
|
35
|
+
session[:session_key] = "session value"
|
36
|
+
end
|
37
|
+
|
38
|
+
def action_which_gets_cookie
|
39
|
+
raise "expected #{params[:expected].inspect}, got #{cookies[:cookie_key].inspect}" unless (cookies[:cookie_key] == params[:expected])
|
40
|
+
render :text => ""
|
41
|
+
end
|
42
|
+
|
43
|
+
def action_which_sets_cookie
|
44
|
+
cookies['cookie_key'] = params[:value]
|
45
|
+
render :text => ""
|
46
|
+
end
|
47
|
+
|
48
|
+
def action_with_partial
|
49
|
+
render :partial => "controller_spec/partial"
|
50
|
+
end
|
51
|
+
|
52
|
+
def action_with_partial_with_object
|
53
|
+
render :partial => "controller_spec/partial", :object => params[:thing]
|
54
|
+
end
|
55
|
+
|
56
|
+
def action_with_partial_with_locals
|
57
|
+
render :partial => "controller_spec/partial", :locals => {:thing => params[:thing]}
|
58
|
+
end
|
59
|
+
|
60
|
+
def action_with_errors_in_template
|
61
|
+
render :template => "controller_spec/action_with_errors_in_template"
|
62
|
+
end
|
63
|
+
|
64
|
+
def action_setting_the_assigns_hash
|
65
|
+
@indirect_assigns_key = :indirect_assigns_key_value
|
66
|
+
end
|
67
|
+
|
68
|
+
def action_setting_flash_after_session_reset
|
69
|
+
reset_session
|
70
|
+
flash[:after_reset] = "available"
|
71
|
+
end
|
72
|
+
|
73
|
+
def action_setting_flash_before_session_reset
|
74
|
+
flash[:before_reset] = 'available'
|
75
|
+
reset_session
|
76
|
+
end
|
77
|
+
|
78
|
+
def action_with_render_update
|
79
|
+
render :update do |page|
|
80
|
+
page.replace :bottom, 'replace_me',
|
81
|
+
:partial => 'non_existent_partial'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def action_with_skipped_before_filter
|
86
|
+
render :text => ""
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class ControllerInheritingFromApplicationControllerController < ApplicationController
|
91
|
+
def action_with_inherited_before_filter
|
92
|
+
render :text => ""
|
93
|
+
end
|
94
|
+
end
|