rspec-rails 2.14.0.rc1 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +12 -0
  3. data/README.md +2 -2
  4. data/features/Autotest.md +24 -0
  5. data/features/Generators.md +24 -0
  6. data/features/GettingStarted.md +84 -0
  7. data/features/README.md +56 -0
  8. data/features/RailsVersions.md +4 -0
  9. data/features/Transactions.md +84 -0
  10. data/features/Upgrade.md +121 -0
  11. data/features/controller_specs/Cookies.md +57 -0
  12. data/features/controller_specs/README.md +45 -0
  13. data/features/controller_specs/anonymous_controller.feature +378 -0
  14. data/features/controller_specs/bypass_rescue.feature +75 -0
  15. data/features/controller_specs/controller_spec.feature +58 -0
  16. data/features/controller_specs/engine_routes.feature +51 -0
  17. data/features/controller_specs/isolation_from_views.feature +87 -0
  18. data/features/controller_specs/render_views.feature +114 -0
  19. data/features/feature_specs/feature_spec.feature +34 -0
  20. data/features/helper_specs/helper_spec.feature +122 -0
  21. data/features/mailer_specs/url_helpers.feature +38 -0
  22. data/features/matchers/README.md +18 -0
  23. data/features/matchers/new_record_matcher.feature +41 -0
  24. data/features/matchers/redirect_to_matcher.feature +40 -0
  25. data/features/matchers/relation_match_array.feature +22 -0
  26. data/features/matchers/render_template_matcher.feature +49 -0
  27. data/features/mocks/mock_model.feature +147 -0
  28. data/features/mocks/stub_model.feature +58 -0
  29. data/features/model_specs/README.md +21 -0
  30. data/features/model_specs/errors_on.feature +51 -0
  31. data/features/model_specs/records.feature +27 -0
  32. data/features/model_specs/transactional_examples.feature +109 -0
  33. data/features/request_specs/request_spec.feature +49 -0
  34. data/features/routing_specs/README.md +16 -0
  35. data/features/routing_specs/be_routable_matcher.feature +80 -0
  36. data/features/routing_specs/engine_routes.feature +38 -0
  37. data/features/routing_specs/named_routes.feature +18 -0
  38. data/features/routing_specs/route_to_matcher.feature +90 -0
  39. data/features/step_definitions/additional_cli_steps.rb +4 -0
  40. data/features/step_definitions/model_steps.rb +3 -0
  41. data/features/support/env.rb +53 -0
  42. data/features/support/rails_versions.rb +4 -0
  43. data/features/view_specs/inferred_controller_path.feature +45 -0
  44. data/features/view_specs/stub_template.feature +51 -0
  45. data/features/view_specs/view_spec.feature +206 -0
  46. data/lib/rspec/rails/example/controller_example_group.rb +2 -4
  47. data/lib/rspec/rails/extensions/active_record/base.rb +8 -2
  48. data/lib/rspec/rails/mocks.rb +15 -10
  49. data/lib/rspec/rails/tasks/rspec.rake +7 -7
  50. data/lib/rspec/rails/version.rb +1 -1
  51. data/spec/autotest/rails_rspec2_spec.rb +36 -0
  52. data/spec/generators/rspec/controller/controller_generator_spec.rb +97 -0
  53. data/spec/generators/rspec/helper/helper_generator_spec.rb +30 -0
  54. data/spec/generators/rspec/install/install_generator_spec.rb +30 -0
  55. data/spec/generators/rspec/integration/integration_generator_spec.rb +44 -0
  56. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +48 -0
  57. data/spec/generators/rspec/model/model_generator_spec.rb +52 -0
  58. data/spec/generators/rspec/observer/observer_generator_spec.rb +21 -0
  59. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +138 -0
  60. data/spec/generators/rspec/view/view_generator_spec.rb +41 -0
  61. data/spec/rspec/rails/assertion_adapter_spec.rb +28 -0
  62. data/spec/rspec/rails/assertion_delegator_spec.rb +43 -0
  63. data/spec/rspec/rails/configuration_spec.rb +26 -0
  64. data/spec/rspec/rails/deprecations_spec.rb +18 -0
  65. data/spec/rspec/rails/example/controller_example_group_spec.rb +100 -0
  66. data/spec/rspec/rails/example/feature_example_group_spec.rb +56 -0
  67. data/spec/rspec/rails/example/helper_example_group_spec.rb +64 -0
  68. data/spec/rspec/rails/example/mailer_example_group_spec.rb +21 -0
  69. data/spec/rspec/rails/example/model_example_group_spec.rb +15 -0
  70. data/spec/rspec/rails/example/request_example_group_spec.rb +17 -0
  71. data/spec/rspec/rails/example/routing_example_group_spec.rb +32 -0
  72. data/spec/rspec/rails/example/view_example_group_spec.rb +220 -0
  73. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
  74. data/spec/rspec/rails/extensions/active_record/base_spec.rb +42 -0
  75. data/spec/rspec/rails/fixture_support_spec.rb +17 -0
  76. data/spec/rspec/rails/matchers/be_a_new_spec.rb +142 -0
  77. data/spec/rspec/rails/matchers/be_new_record_spec.rb +33 -0
  78. data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
  79. data/spec/rspec/rails/matchers/be_valid_spec.rb +44 -0
  80. data/spec/rspec/rails/matchers/errors_on_spec.rb +38 -0
  81. data/spec/rspec/rails/matchers/has_spec.rb +29 -0
  82. data/spec/rspec/rails/matchers/have_rendered_spec.rb +93 -0
  83. data/spec/rspec/rails/matchers/redirect_to_spec.rb +80 -0
  84. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +31 -0
  85. data/spec/rspec/rails/matchers/route_to_spec.rb +151 -0
  86. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +22 -0
  87. data/spec/rspec/rails/mocks/mock_model_spec.rb +379 -0
  88. data/spec/rspec/rails/mocks/stub_model_spec.rb +154 -0
  89. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +32 -0
  90. data/spec/rspec/rails/view_rendering_spec.rb +111 -0
  91. data/spec/spec_helper.rb +31 -0
  92. data/spec/support/ar_classes.rb +42 -0
  93. data/spec/support/helpers.rb +20 -0
  94. data/spec/support/matchers.rb +9 -0
  95. data/spec/support/null_object.rb +6 -0
  96. metadata +192 -18
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ # Generators are not automatically loaded by Rails
4
+ require 'generators/rspec/view/view_generator'
5
+
6
+ describe Rspec::Generators::ViewGenerator do
7
+ # Tell the generator where to put its output (what it thinks of as Rails.root)
8
+ destination File.expand_path("../../../../../tmp", __FILE__)
9
+
10
+ before { prepare_destination }
11
+
12
+ describe 'with default template engine' do
13
+ it 'generates a spec for the supplied action' do
14
+ run_generator %w(posts index)
15
+ file('spec/views/posts/index.html.erb_spec.rb').tap do |f|
16
+ f.should contain(/require 'spec_helper'/)
17
+ f.should contain(/describe "posts\/index"/)
18
+ end
19
+ end
20
+
21
+ describe 'with a nested resource' do
22
+ it 'generates a spec for the supplied action' do
23
+ run_generator %w(admin/posts index)
24
+ file('spec/views/admin/posts/index.html.erb_spec.rb').tap do |f|
25
+ f.should contain(/require 'spec_helper'/)
26
+ f.should contain(/describe "admin\/posts\/index"/)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'with a specified template engine' do
33
+ it 'generates a spec for the supplied action' do
34
+ run_generator %w(posts index --template_engine haml)
35
+ file('spec/views/posts/index.html.haml_spec.rb').tap do |f|
36
+ f.should contain(/require 'spec_helper'/)
37
+ f.should contain(/describe "posts\/index"/)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpec::Rails::TestUnitAssertionAdapter do
4
+ include RSpec::Rails::TestUnitAssertionAdapter
5
+
6
+ Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk)/}.each do |m|
7
+ if m.to_s == "assert_equal"
8
+ it "exposes #{m} to host examples" do
9
+ assert_equal 3,3
10
+ expect do
11
+ assert_equal 3,4
12
+ end.to raise_error(ActiveSupport::TestCase::Assertion)
13
+ end
14
+ else
15
+ it "exposes #{m} to host examples" do
16
+ methods.should include(m)
17
+ end
18
+ end
19
+ end
20
+
21
+ it "does not expose internal methods of MiniTest" do
22
+ methods.should_not include("_assertions")
23
+ end
24
+
25
+ it "does not expose MiniTest's message method" do
26
+ methods.should_not include("message")
27
+ end
28
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpec::Rails::AssertionDelegator do
4
+ it "provides a module that delegates assertion methods to an isolated class" do
5
+ klass = Class.new {
6
+ include RSpec::Rails::AssertionDelegator.new(Test::Unit::Assertions)
7
+ }
8
+
9
+ expect(klass.new).to respond_to(:assert)
10
+ end
11
+
12
+ it "delegates back to the including instance for methods the assertion module requires" do
13
+ assertions = Module.new {
14
+ def has_thing?(thing)
15
+ self.things.include?(thing)
16
+ end
17
+ }
18
+
19
+ klass = Class.new {
20
+ include RSpec::Rails::AssertionDelegator.new(assertions)
21
+
22
+ def things
23
+ [:a]
24
+ end
25
+ }
26
+
27
+ expect(klass.new).to have_thing(:a)
28
+ expect(klass.new).not_to have_thing(:b)
29
+ end
30
+
31
+ it "does not delegate method_missing" do
32
+ assertions = Module.new {
33
+ def method_missing(method, *args)
34
+ end
35
+ }
36
+
37
+ klass = Class.new {
38
+ include RSpec::Rails::AssertionDelegator.new(assertions)
39
+ }
40
+
41
+ expect { klass.new.abc123 }.to raise_error(NoMethodError)
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe "configuration" do
4
+ before do
5
+ @orig_render_views = RSpec.configuration.render_views?
6
+ end
7
+
8
+ after do
9
+ RSpec.configuration.render_views = @orig_render_views
10
+ end
11
+
12
+ describe "#render_views?" do
13
+ it "is false by default" do
14
+ RSpec.configuration.render_views?.should be_false
15
+ end
16
+ end
17
+
18
+ describe "#render_views" do
19
+ it "sets render_views? to return true" do
20
+ RSpec.configuration.render_views = false
21
+ RSpec.configuration.render_views
22
+
23
+ RSpec.configuration.render_views?.should be_true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "rspec-rails-2 deprecations" do
4
+ context "controller specs" do
5
+ describe "::integrate_views" do
6
+ let(:group) do
7
+ RSpec::Core::ExampleGroup.describe do
8
+ include RSpec::Rails::ControllerExampleGroup
9
+ end
10
+ end
11
+
12
+ it "is deprecated" do
13
+ RSpec.should_receive(:deprecate)
14
+ group.integrate_views
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,100 @@
1
+ require "spec_helper"
2
+
3
+ class ::ApplicationController
4
+ end
5
+
6
+ module RSpec::Rails
7
+ describe ControllerExampleGroup do
8
+ it { should be_included_in_files_in('./spec/controllers/') }
9
+ it { should be_included_in_files_in('.\\spec\\controllers\\') }
10
+
11
+ let(:group) do
12
+ RSpec::Core::ExampleGroup.describe do
13
+ include ControllerExampleGroup
14
+ end
15
+ end
16
+
17
+ it "includes routing matchers" do
18
+ group.included_modules.should include(RSpec::Rails::Matchers::RoutingMatchers)
19
+ end
20
+
21
+ it "adds :type => :controller to the metadata" do
22
+ group.metadata[:type].should eq(:controller)
23
+ end
24
+
25
+ context "with implicit subject" do
26
+ it "uses the controller as the subject" do
27
+ controller = double('controller')
28
+ example = group.new
29
+ example.stub(:controller => controller)
30
+ example.subject.should == controller
31
+ end
32
+ end
33
+
34
+ context "with explicit subject" do
35
+ it "uses the specified subject instead of the controller" do
36
+ group.subject { 'explicit' }
37
+ example = group.new
38
+ example.subject.should == 'explicit'
39
+ end
40
+ end
41
+
42
+ describe "#controller" do
43
+ before do
44
+ group.class_eval do
45
+ controller(Class.new) { }
46
+ end
47
+ end
48
+
49
+ it "delegates named route helpers to the underlying controller" do
50
+ controller = double('controller')
51
+ controller.stub(:foos_url).and_return('http://test.host/foos')
52
+
53
+ example = group.new
54
+ example.stub(:controller => controller)
55
+
56
+ # As in the routing example spec, this is pretty invasive, but not sure
57
+ # how to do it any other way as the correct operation relies on before
58
+ # hooks
59
+ routes = ActionDispatch::Routing::RouteSet.new
60
+ routes.draw { resources :foos }
61
+ example.instance_variable_set(:@orig_routes, routes)
62
+
63
+ example.foos_url.should eq('http://test.host/foos')
64
+ end
65
+ end
66
+
67
+ describe "#bypass_rescue" do
68
+ it "overrides the rescue_with_handler method on the controller to raise submitted error" do
69
+ example = group.new
70
+ example.instance_variable_set("@controller", Class.new { def rescue_with_handler(e); end }.new)
71
+ example.bypass_rescue
72
+ expect do
73
+ example.controller.rescue_with_handler(RuntimeError.new("foo"))
74
+ end.to raise_error("foo")
75
+ end
76
+ end
77
+
78
+ describe "with inferred anonymous controller" do
79
+ before do
80
+ group.stub(:controller_class).and_return(Class.new)
81
+ end
82
+
83
+ it "infers the anonymous controller class when infer_base_class_for_anonymous_controllers is true" do
84
+ RSpec.configuration.stub(:infer_base_class_for_anonymous_controllers?).and_return(true)
85
+ group.controller { }
86
+
87
+ controller_class = group.metadata[:example_group][:described_class]
88
+ controller_class.superclass.should eq(group.controller_class)
89
+ end
90
+
91
+ it "sets the anonymous controller class to ApplicationController when infer_base_class_for_anonymous_controllers is false" do
92
+ RSpec.configuration.stub(:infer_base_class_for_anonymous_controllers?).and_return(false)
93
+ group.controller { }
94
+
95
+ controller_class = group.metadata[:example_group][:described_class]
96
+ controller_class.superclass.should eq(ApplicationController)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ module RSpec::Rails
4
+ describe FeatureExampleGroup do
5
+ it { should be_included_in_files_in('./spec/features/') }
6
+ it { should be_included_in_files_in('.\\spec\\features\\') }
7
+
8
+ it "adds :type => :feature to the metadata" do
9
+ group = RSpec::Core::ExampleGroup.describe do
10
+ include FeatureExampleGroup
11
+ end
12
+
13
+ expect(group.metadata[:type]).to eq(:feature)
14
+ end
15
+
16
+ it "includes Rails route helpers" do
17
+ Rails.application.routes.draw do
18
+ get "/foo", :as => :foo, :to => "foo#bar"
19
+ end
20
+
21
+ group = RSpec::Core::ExampleGroup.describe do
22
+ include FeatureExampleGroup
23
+ end
24
+
25
+ expect(group.new.foo_path).to eq("/foo")
26
+ expect(group.new.foo_url).to eq("http://www.example.com/foo")
27
+ end
28
+
29
+ describe "#visit" do
30
+ it "raises an error informing about missing Capybara" do
31
+ group = RSpec::Core::ExampleGroup.describe do
32
+ include FeatureExampleGroup
33
+ end
34
+
35
+ expect {
36
+ group.new.visit('/foobar')
37
+ }.to raise_error(/Capybara not loaded/)
38
+ end
39
+
40
+ it "is resistant to load order errors" do
41
+ capybara = Module.new do
42
+ def visit(url)
43
+ "success: #{url}"
44
+ end
45
+ end
46
+
47
+ group = RSpec::Core::ExampleGroup.describe do
48
+ include capybara
49
+ include FeatureExampleGroup
50
+ end
51
+
52
+ expect(group.new.visit("/foo")).to eq("success: /foo")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ module RSpec::Rails
4
+ describe HelperExampleGroup do
5
+ module ::FoosHelper; end
6
+ subject { HelperExampleGroup }
7
+
8
+ it { should be_included_in_files_in('./spec/helpers/') }
9
+ it { should be_included_in_files_in('.\\spec\\helpers\\') }
10
+
11
+ it "provides a controller_path based on the helper module's name" do
12
+ helper_spec = Object.new.extend HelperExampleGroup
13
+ helper_spec.stub_chain(:example, :example_group, :described_class).and_return(FoosHelper)
14
+ helper_spec.__send__(:_controller_path).should == "foos"
15
+ end
16
+
17
+ it "adds :type => :helper to the metadata" do
18
+ group = RSpec::Core::ExampleGroup.describe do
19
+ include HelperExampleGroup
20
+ end
21
+ group.metadata[:type].should eq(:helper)
22
+ end
23
+
24
+ describe "#helper" do
25
+ it "returns the instance of AV::Base provided by AV::TC::Behavior" do
26
+ helper_spec = Object.new.extend HelperExampleGroup
27
+ helper_spec.should_receive(:view_assigns)
28
+ av_tc_b_view = double('_view')
29
+ av_tc_b_view.should_receive(:assign)
30
+ helper_spec.stub(:_view) { av_tc_b_view }
31
+ helper_spec.helper.should eq(av_tc_b_view)
32
+ end
33
+
34
+ before do
35
+ Object.const_set(:ApplicationHelper, Module.new)
36
+ end
37
+
38
+ after do
39
+ Object.__send__(:remove_const, :ApplicationHelper)
40
+ end
41
+
42
+ it "includes ApplicationHelper" do
43
+ group = RSpec::Core::ExampleGroup.describe do
44
+ include HelperExampleGroup
45
+ def _view
46
+ ActionView::Base.new
47
+ end
48
+ end
49
+ group.new.helper.should be_kind_of(ApplicationHelper)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe HelperExampleGroup::ClassMethods do
55
+ describe "determine_default_helper_class" do
56
+ it "returns the helper module passed to describe" do
57
+ helper_spec = Object.new.extend HelperExampleGroup::ClassMethods
58
+ helper_spec.stub(:described_class) { FoosHelper }
59
+ helper_spec.determine_default_helper_class("ignore this").
60
+ should eq(FoosHelper)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ module RSpec::Rails
4
+ describe MailerExampleGroup do
5
+ module ::Rails; end
6
+ before do
7
+ Rails.stub_chain(:application, :routes, :url_helpers).and_return(Rails)
8
+ Rails.stub_chain(:configuration, :action_mailer, :default_url_options).and_return({})
9
+ end
10
+
11
+ it { should be_included_in_files_in('./spec/mailers/') }
12
+ it { should be_included_in_files_in('.\\spec\\mailers\\') }
13
+
14
+ it "adds :type => :mailer to the metadata" do
15
+ group = RSpec::Core::ExampleGroup.describe do
16
+ include MailerExampleGroup
17
+ end
18
+ group.metadata[:type].should eq(:mailer)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ module RSpec::Rails
4
+ describe ModelExampleGroup do
5
+ it { should be_included_in_files_in('./spec/models/') }
6
+ it { should be_included_in_files_in('.\\spec\\models\\') }
7
+
8
+ it "adds :type => :model to the metadata" do
9
+ group = RSpec::Core::ExampleGroup.describe do
10
+ include ModelExampleGroup
11
+ end
12
+ group.metadata[:type].should eq(:model)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ module RSpec::Rails
4
+ describe RequestExampleGroup do
5
+ it { should be_included_in_files_in('./spec/requests/') }
6
+ it { should be_included_in_files_in('./spec/integration/') }
7
+ it { should be_included_in_files_in('.\\spec\\requests\\') }
8
+ it { should be_included_in_files_in('.\\spec\\integration\\') }
9
+
10
+ it "adds :type => :request to the metadata" do
11
+ group = RSpec::Core::ExampleGroup.describe do
12
+ include RequestExampleGroup
13
+ end
14
+ group.metadata[:type].should eq(:request)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ module RSpec::Rails
4
+ describe RoutingExampleGroup do
5
+ it { should be_included_in_files_in('./spec/routing/') }
6
+ it { should be_included_in_files_in('.\\spec\\routing\\') }
7
+
8
+ it "adds :type => :routing to the metadata" do
9
+ group = RSpec::Core::ExampleGroup.describe do
10
+ include RoutingExampleGroup
11
+ end
12
+ group.metadata[:type].should eq(:routing)
13
+ end
14
+
15
+ describe "named routes" do
16
+ it "delegates them to the route_set" do
17
+ group = RSpec::Core::ExampleGroup.describe do
18
+ include RoutingExampleGroup
19
+ end
20
+
21
+ example = group.new
22
+
23
+ # Yes, this is quite invasive
24
+ url_helpers = double('url_helpers', :foo_path => "foo")
25
+ routes = double('routes', :url_helpers => url_helpers)
26
+ example.stub(:routes => routes)
27
+
28
+ example.foo_path.should == "foo"
29
+ end
30
+ end
31
+ end
32
+ end