rspec-rails 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -1
  4. data/Capybara.md +1 -3
  5. data/Changelog.md +126 -58
  6. data/README.md +31 -4
  7. data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
  8. data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
  9. data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
  10. data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
  11. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +21 -1
  12. data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
  13. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +1 -1
  14. data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
  15. data/lib/generators/rspec/observer/templates/observer_spec.rb +1 -1
  16. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +11 -3
  17. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +4 -3
  18. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  19. data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -4
  20. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
  21. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  22. data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
  23. data/lib/rspec/rails.rb +1 -8
  24. data/lib/rspec/rails/configuration.rb +72 -0
  25. data/lib/rspec/rails/example.rb +0 -64
  26. data/lib/rspec/rails/example/controller_example_group.rb +16 -12
  27. data/lib/rspec/rails/example/feature_example_group.rb +0 -2
  28. data/lib/rspec/rails/example/helper_example_group.rb +0 -2
  29. data/lib/rspec/rails/example/mailer_example_group.rb +0 -1
  30. data/lib/rspec/rails/example/model_example_group.rb +0 -4
  31. data/lib/rspec/rails/example/request_example_group.rb +0 -2
  32. data/lib/rspec/rails/example/routing_example_group.rb +0 -2
  33. data/lib/rspec/rails/example/view_example_group.rb +1 -2
  34. data/lib/rspec/rails/extensions.rb +0 -1
  35. data/lib/rspec/rails/fixture_support.rb +0 -8
  36. data/lib/rspec/rails/matchers.rb +1 -0
  37. data/lib/rspec/rails/matchers/have_http_status.rb +355 -0
  38. data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
  39. data/lib/rspec/rails/tasks/rspec.rake +12 -5
  40. data/lib/rspec/rails/version.rb +1 -1
  41. data/lib/rspec/rails/view_rendering.rb +6 -34
  42. metadata +42 -316
  43. metadata.gz.sig +0 -0
  44. data/features/Generators.md +0 -25
  45. data/features/GettingStarted.md +0 -84
  46. data/features/README.md +0 -48
  47. data/features/RailsVersions.md +0 -4
  48. data/features/Transactions.md +0 -84
  49. data/features/Upgrade.md +0 -121
  50. data/features/controller_specs/Cookies.md +0 -57
  51. data/features/controller_specs/README.md +0 -45
  52. data/features/controller_specs/anonymous_controller.feature +0 -436
  53. data/features/controller_specs/bypass_rescue.feature +0 -75
  54. data/features/controller_specs/controller_spec.feature +0 -58
  55. data/features/controller_specs/engine_routes.feature +0 -51
  56. data/features/controller_specs/isolation_from_views.feature +0 -87
  57. data/features/controller_specs/render_views.feature +0 -114
  58. data/features/directory_structure.feature +0 -71
  59. data/features/feature_specs/feature_spec.feature +0 -35
  60. data/features/helper_specs/helper_spec.feature +0 -122
  61. data/features/mailer_specs/url_helpers.feature +0 -38
  62. data/features/matchers/README.md +0 -18
  63. data/features/matchers/new_record_matcher.feature +0 -41
  64. data/features/matchers/redirect_to_matcher.feature +0 -40
  65. data/features/matchers/relation_match_array.feature +0 -27
  66. data/features/matchers/render_template_matcher.feature +0 -49
  67. data/features/mocks/mock_model.feature +0 -147
  68. data/features/mocks/stub_model.feature +0 -58
  69. data/features/model_specs/README.md +0 -21
  70. data/features/model_specs/errors_on.feature +0 -51
  71. data/features/model_specs/records.feature +0 -27
  72. data/features/model_specs/transactional_examples.feature +0 -109
  73. data/features/request_specs/request_spec.feature +0 -49
  74. data/features/routing_specs/README.md +0 -16
  75. data/features/routing_specs/be_routable_matcher.feature +0 -80
  76. data/features/routing_specs/engine_routes.feature +0 -38
  77. data/features/routing_specs/named_routes.feature +0 -18
  78. data/features/routing_specs/route_to_matcher.feature +0 -90
  79. data/features/step_definitions/additional_cli_steps.rb +0 -4
  80. data/features/step_definitions/model_steps.rb +0 -3
  81. data/features/support/capybara.rb +0 -7
  82. data/features/support/env.rb +0 -53
  83. data/features/support/rails_versions.rb +0 -4
  84. data/features/support/rubinius.rb +0 -6
  85. data/features/view_specs/inferred_controller_path.feature +0 -45
  86. data/features/view_specs/stub_template.feature +0 -51
  87. data/features/view_specs/view_spec.feature +0 -206
  88. data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
  89. data/lib/rspec/rails/mocks.rb +0 -272
  90. data/lib/rspec/rails/vendor/webrat.rb +0 -33
  91. data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
  92. data/spec/generators/rspec/feature/feature_generator_spec.rb +0 -43
  93. data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
  94. data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
  95. data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -32
  96. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
  97. data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
  98. data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
  99. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
  100. data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
  101. data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
  102. data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
  103. data/spec/rspec/rails/configuration_spec.rb +0 -26
  104. data/spec/rspec/rails/deprecations_spec.rb +0 -18
  105. data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -159
  106. data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
  107. data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
  108. data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
  109. data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
  110. data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
  111. data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
  112. data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
  113. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
  114. data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
  115. data/spec/rspec/rails/fixture_support_spec.rb +0 -17
  116. data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
  117. data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
  118. data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
  119. data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -73
  120. data/spec/rspec/rails/matchers/has_spec.rb +0 -29
  121. data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
  122. data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
  123. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
  124. data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
  125. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
  126. data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -400
  127. data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
  128. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
  129. data/spec/rspec/rails/view_rendering_spec.rb +0 -111
  130. data/spec/spec_helper.rb +0 -33
  131. data/spec/support/ar_classes.rb +0 -42
  132. data/spec/support/helpers.rb +0 -34
  133. data/spec/support/matchers.rb +0 -9
  134. data/spec/support/null_object.rb +0 -6
@@ -1,38 +0,0 @@
1
- Feature: URL helpers in mailer examples
2
-
3
- Scenario: using URL helpers with default options
4
- Given a file named "config/initializers/mailer_defaults.rb" with:
5
- """ruby
6
- Rails.configuration.action_mailer.default_url_options = { :host => 'example.com' }
7
- """
8
- And a file named "spec/mailers/notifications_spec.rb" with:
9
- """ruby
10
- require 'spec_helper'
11
-
12
- describe Notifications do
13
- it 'should have access to URL helpers' do
14
- expect { gadgets_url }.not_to raise_error
15
- end
16
- end
17
- """
18
- When I run `rspec spec`
19
- Then the examples should all pass
20
-
21
- Scenario: using URL helpers without default options
22
- Given a file named "config/initializers/mailer_defaults.rb" with:
23
- """ruby
24
- # no default options
25
- """
26
- And a file named "spec/mailers/notifications_spec.rb" with:
27
- """ruby
28
- require 'spec_helper'
29
-
30
- describe Notifications do
31
- it 'should have access to URL helpers' do
32
- expect { gadgets_url :host => 'example.com' }.not_to raise_error
33
- expect { gadgets_url }.to raise_error
34
- end
35
- end
36
- """
37
- When I run `rspec spec`
38
- Then the examples should all pass
@@ -1,18 +0,0 @@
1
- rspec-rails offers a number of custom matchers, most of which are
2
- rspec-compatible wrappers for Rails' assertions.
3
-
4
- ### redirects
5
-
6
- # delegates to assert_redirected_to
7
- expect(response).to redirect_to(path)
8
-
9
- ### templates
10
-
11
- # delegates to assert_template
12
- expect(response).to render_template(template_name)
13
-
14
- ### assigned objects
15
-
16
- # passes if assigns(:widget) is an instance of Widget
17
- # and it is not persisted
18
- expect(assigns(:widget)).to be_a_new(Widget)
@@ -1,41 +0,0 @@
1
- Feature: be_a_new matcher
2
-
3
- The `be_a_new` matcher accepts a class and passes if the subject is an
4
- instance of that class that returns false to persisted?
5
-
6
- You can also chain `with` on `be_a_new` with a hash of attributes to specify
7
- the subject has equal attributes.
8
-
9
- Scenario: example spec with four be_a_new possibilities
10
- Given a file named "spec/models/widget_spec.rb" with:
11
- """ruby
12
- require "spec_helper"
13
-
14
- describe Widget do
15
- context "when initialized" do
16
- subject(:widget) { Widget.new }
17
-
18
- it "is a new widget" do
19
- expect(widget).to be_a_new(Widget)
20
- end
21
-
22
- it "is not a new string" do
23
- expect(widget).not_to be_a_new(String)
24
- end
25
- end
26
-
27
- context "when saved" do
28
- subject(:widget) { Widget.create }
29
-
30
- it "is not a new widget" do
31
- expect(widget).not_to be_a_new(Widget)
32
- end
33
-
34
- it "is not a new string" do
35
- expect(widget).not_to be_a_new(String)
36
- end
37
- end
38
- end
39
- """
40
- When I run `rspec spec/models/widget_spec.rb`
41
- Then the examples should all pass
@@ -1,40 +0,0 @@
1
- Feature: redirect_to matcher
2
-
3
- The `redirect_to` matcher is used to specify that a request redirects to a
4
- given template or action. It delegates to
5
- [`assert_redirected_to`](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/ResponseAssertions.html#method-i-assert_redirected_to).
6
-
7
- It is available in controller specs (spec/controllers) and request
8
- specs (spec/requests).
9
-
10
- Scenario: redirect_to with four possible options
11
- Given a file named "spec/controllers/widgets_controller_spec.rb" with:
12
- """ruby
13
- require "spec_helper"
14
-
15
- describe WidgetsController do
16
-
17
- describe "#create" do
18
- subject { post :create, :widget => { :name => "Foo" } }
19
-
20
- it "redirects to widget_url(@widget)" do
21
- expect(subject).to redirect_to(widget_url(assigns(:widget)))
22
- end
23
-
24
- it "redirects_to :action => :show" do
25
- expect(subject).to redirect_to :action => :show,
26
- :id => assigns(:widget).id
27
- end
28
-
29
- it "redirects_to(@widget)" do
30
- expect(subject).to redirect_to(assigns(:widget))
31
- end
32
-
33
- it "redirects_to /widgets/:id" do
34
- expect(subject).to redirect_to("/widgets/#{assigns(:widget).id}")
35
- end
36
- end
37
- end
38
- """
39
- When I run `rspec spec/controllers/widgets_controller_spec.rb`
40
- Then the examples should all pass
@@ -1,27 +0,0 @@
1
- Feature: ActiveRecord::Relation match array
2
-
3
- The `match_array` matcher can be used with an `ActiveRecord::Relation`
4
- (scope). The assertion will pass if the scope would return all of the
5
- elements specified in the array on the right hand side.
6
-
7
- Scenario: example spec with relation match_array matcher
8
- Given a file named "spec/models/widget_spec.rb" with:
9
- """ruby
10
- require "spec_helper"
11
-
12
- describe Widget do
13
- let!(:widgets) { Array.new(3) { Widget.create } }
14
-
15
- if ::Rails::VERSION::STRING >= '4'
16
- subject { Widget.all }
17
- else
18
- subject { Widget.scoped }
19
- end
20
-
21
- it "returns all widgets in any order" do
22
- expect(subject).to match_array(widgets)
23
- end
24
- end
25
- """
26
- When I run `rspec spec/models/widget_spec.rb`
27
- Then the examples should all pass
@@ -1,49 +0,0 @@
1
- Feature: render_template matcher
2
-
3
- The `render_template` matcher is used to specify that a request renders a
4
- given template. It delegates to
5
- [`assert_template`](http://api.rubyonrails.org/classes/ActionController/TemplateAssertions.html#method-i-assert_template)
6
-
7
- It is available in controller specs (spec/controllers) and request
8
- specs (spec/requests).
9
-
10
- NOTE: use `redirect_to(:action => 'new')` for redirects, not `render_template`.
11
-
12
- Scenario: render_template with three possible options
13
- Given a file named "spec/controllers/gadgets_spec.rb" with:
14
- """ruby
15
- require "spec_helper"
16
-
17
- describe GadgetsController do
18
- describe "GET #index" do
19
- subject { get :index }
20
-
21
- it "renders the index template" do
22
- expect(subject).to render_template(:index)
23
- expect(subject).to render_template("index")
24
- expect(subject).to render_template("gadgets/index")
25
- end
26
- end
27
- end
28
- """
29
- When I run `rspec spec/controllers/gadgets_spec.rb`
30
- Then the examples should all pass
31
-
32
- Scenario: render_template in a view spec
33
- Given a file named "spec/views/gadgets/index.html.erb_spec.rb" with:
34
- """ruby
35
- require "spec_helper"
36
-
37
- describe "gadgets/index" do
38
- it "renders the index template" do
39
- assign(:gadgets, [stub_model(Gadget)])
40
- render
41
-
42
- expect(view).to render_template(:index)
43
- expect(view).to render_template("index")
44
- expect(view).to render_template("gadgets/index")
45
- end
46
- end
47
- """
48
- When I run `rspec spec/views`
49
- Then the examples should all pass
@@ -1,147 +0,0 @@
1
- Feature: mock_model
2
-
3
- The `mock_model` method generates a test double that acts like an instance of
4
- `ActiveModel`. This is different from the `stub_model` method which generates
5
- an instance of a real model class.
6
-
7
- The benefit of `mock_model` over `stub_model` is that it is a true double, so
8
- the examples are not dependent on the behavior (or mis-behavior), or even the
9
- existence of any other code. If you're working on a controller spec and you
10
- need a model that doesn't exist, you can pass `mock_model` a string and the
11
- generated object will act as though its an instance of the class named by
12
- that string.
13
-
14
- Scenario: passing a string that represents a non-existent constant
15
- Given a file named "spec/models/car_spec.rb" with:
16
- """ruby
17
- require "spec_helper"
18
-
19
- describe "mock_model('Car') with no Car constant in existence" do
20
- it "generates a constant" do
21
- expect(Object.const_defined?(:Car)).to be_falsey
22
- mock_model("Car")
23
- expect(Object.const_defined?(:Car)).to be_truthy
24
- end
25
-
26
- describe "generates an object that ..." do
27
- it "returns the correct name" do
28
- car = mock_model("Car")
29
- expect(car.class.name).to eq("Car")
30
- end
31
-
32
- it "says it is a Car" do
33
- car = mock_model("Car")
34
- expect(car).to be_a(Car)
35
- end
36
- end
37
- end
38
- """
39
- When I run `rspec spec/models/car_spec.rb`
40
- Then the examples should all pass
41
-
42
- Scenario: passing a string that represents an existing constant
43
- Given a file named "spec/models/widget_spec.rb" with:
44
- """ruby
45
- require "spec_helper"
46
-
47
- describe Widget do
48
- it "uses the existing constant" do
49
- widget = mock_model("Widget")
50
- expect(widget).to be_a(Widget)
51
- end
52
- end
53
- """
54
- When I run `rspec spec/models/widget_spec.rb`
55
- Then the examples should all pass
56
-
57
- Scenario: passing a class that does not extend ActiveModel::Naming
58
- Given a file named "spec/models/string_spec.rb" with:
59
- """ruby
60
- require "spec_helper"
61
-
62
- describe String do
63
- it "raises" do
64
- expect { mock_model(String) }.to raise_exception
65
- end
66
- end
67
- """
68
- When I run `rspec spec/models/string_spec.rb`
69
- Then the examples should all pass
70
-
71
- Scenario: passing an Active Record constant
72
- Given a file named "spec/models/widget_spec.rb" with:
73
- """ruby
74
- require "spec_helper"
75
-
76
- describe Widget do
77
- let(:widget) { mock_model(Widget) }
78
-
79
- it "is valid by default" do
80
- expect(widget).to be_valid
81
- end
82
-
83
- it "is not a new record by default" do
84
- expect(widget).not_to be_new_record
85
- end
86
-
87
- it "can be converted to a new record" do
88
- expect(widget.as_new_record).to be_new_record
89
- end
90
-
91
- it "sets :id to nil upon destroy" do
92
- widget.destroy
93
- expect(widget.id).to be_nil
94
- end
95
- end
96
- """
97
- When I run `rspec spec/models/widget_spec.rb`
98
- Then the examples should all pass
99
-
100
- Scenario: passing an Active Record constant with method stubs
101
- Given a file named "spec/models/widget_spec.rb" with:
102
- """ruby
103
- require "spec_helper"
104
-
105
- describe "mock_model(Widget) with stubs" do
106
- let(:widget) do
107
- mock_model Widget, :foo => "bar",
108
- :save => true,
109
- :update_attributes => false
110
- end
111
-
112
- it "supports stubs for methods that don't exist in ActiveModel or ActiveRecord" do
113
- expect(widget.foo).to eq("bar")
114
- end
115
-
116
- it "supports stubs for methods that do exist" do
117
- expect(widget.save).to eq(true)
118
- expect(widget.update_attributes).to be_falsey
119
- end
120
-
121
- describe "#errors" do
122
- context "with update_attributes => false" do
123
- it "is not empty" do
124
- expect(widget.errors).not_to be_empty
125
- end
126
- end
127
- end
128
- end
129
- """
130
- When I run `rspec spec/models/widget_spec.rb`
131
- Then the examples should all pass
132
-
133
- Scenario: mock_model outside rails
134
- Given a file named "mock_model_outside_rails_spec.rb" with:
135
- """ruby
136
- require 'rspec/rails/mocks'
137
-
138
- describe "Foo" do
139
- it "is mockable" do
140
- foo = mock_model("Foo")
141
- expect(foo.id).to eq(1001)
142
- expect(foo.to_param).to eq("1001")
143
- end
144
- end
145
- """
146
- When I run `rspec mock_model_outside_rails_spec.rb`
147
- Then the examples should all pass
@@ -1,58 +0,0 @@
1
- Feature: stub_model
2
-
3
- The stub_model method generates an instance of a Active Model model.
4
-
5
- While you can use stub_model in any example (model, view, controller,
6
- helper), it is especially useful in view examples, which are inherently
7
- more state-based than interaction-based.
8
-
9
- Scenario: passing an Active Record constant with a hash of stubs
10
- Given a file named "spec/models/widget_spec.rb" with:
11
- """ruby
12
- require "spec_helper"
13
-
14
- describe "stub_model(Widget) with a hash of stubs" do
15
- let(:widget) do
16
- stub_model Widget, :id => 5, :random_attribute => true
17
- end
18
-
19
- it "stubs :id" do
20
- expect(widget.id).to eql(5)
21
- end
22
-
23
- it "stubs :random_attribute" do
24
- expect(widget.random_attribute).to be_truthy
25
- end
26
-
27
- it "returns false for new_record? if :id is set" do
28
- expect(widget).not_to be_new_record
29
- end
30
-
31
- it "can be converted to a new record" do
32
- widget.as_new_record
33
- expect(widget).to be_new_record
34
- end
35
- end
36
- """
37
- When I run `rspec spec/models/widget_spec.rb`
38
- Then the examples should all pass
39
-
40
- Scenario: passing an Active Record constant with a block of stubs
41
- Given a file named "spec/models/widget_spec.rb" with:
42
- """ruby
43
- require "spec_helper"
44
-
45
- describe "stub_model(Widget) with a block of stubs" do
46
- let(:widget) do
47
- stub_model Widget do |widget|
48
- widget.id = 5
49
- end
50
- end
51
-
52
- it "stubs :id" do
53
- expect(widget.id).to eql(5)
54
- end
55
- end
56
- """
57
- When I run `rspec spec/models/widget_spec.rb`
58
- Then the examples should all pass
@@ -1,21 +0,0 @@
1
- Model specs live in `spec/models` or any example group with
2
- `:type => :model`.
3
-
4
- A model spec is a thin wrapper for an ActiveSupport::TestCase, and includes all
5
- of the behavior and assertions that it provides, in addition to RSpec's own
6
- behavior and expectations.
7
-
8
- ## Examples
9
-
10
- require "spec_helper"
11
-
12
- describe Post do
13
- context "with 2 or more comments" do
14
- it "orders them in reverse chronologically" do
15
- post = Post.create!
16
- comment1 = post.comments.create!(:body => "first comment")
17
- comment2 = post.comments.create!(:body => "second comment")
18
- expect(post.reload.comments).to eq([comment2, comment1])
19
- end
20
- end
21
- end