rspec-rails 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile-3-0-stable +6 -0
  3. data/Gemfile-3.0.0 +3 -0
  4. data/Gemfile-3.0.3 +3 -0
  5. data/{Gemfile → Gemfile-base} +4 -8
  6. data/Gemfile-master +5 -0
  7. data/History.md +1 -114
  8. data/README.md +2 -2
  9. data/Rakefile +9 -7
  10. data/Thorfile +7 -0
  11. data/Upgrade.md +1 -63
  12. data/features/.nav +5 -4
  13. data/features/Autotest.md +15 -8
  14. data/features/Changelog.md +127 -0
  15. data/features/Upgrade.md +60 -0
  16. data/features/controller_specs/README.md +3 -2
  17. data/features/controller_specs/anonymous_controller.feature +2 -2
  18. data/features/controller_specs/isolation_from_views.feature +2 -2
  19. data/features/controller_specs/render_views.feature +42 -60
  20. data/features/helper_specs/helper_spec.feature +3 -3
  21. data/features/mailer_specs/url_helpers.feature +2 -2
  22. data/features/matchers/new_record_matcher.feature +2 -2
  23. data/features/matchers/redirect_to_matcher.feature +1 -1
  24. data/features/matchers/render_template_matcher.feature +1 -1
  25. data/features/mocks/mock_model.feature +5 -5
  26. data/features/mocks/stub_model.feature +2 -2
  27. data/features/model_specs/errors_on.feature +1 -1
  28. data/features/model_specs/transactional_examples.feature +4 -4
  29. data/features/routing_specs/be_routable_matcher.feature +3 -3
  30. data/features/routing_specs/named_routes.feature +1 -1
  31. data/features/routing_specs/route_to_matcher.feature +1 -1
  32. data/features/step_definitions/{rspec_steps.rb → additional_cli_steps.rb} +1 -2
  33. data/features/view_specs/inferred_controller_path.feature +3 -3
  34. data/features/view_specs/stub_template.feature +2 -2
  35. data/features/view_specs/view_spec.feature +8 -8
  36. data/lib/generators/rspec/integration/templates/request_spec.rb +2 -2
  37. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +1 -1
  38. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
  39. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
  40. data/lib/rspec/rails/example.rb +5 -3
  41. data/lib/rspec/rails/example/controller_example_group.rb +10 -6
  42. data/lib/rspec/rails/example/request_example_group.rb +1 -1
  43. data/lib/rspec/rails/mocks.rb +6 -0
  44. data/lib/rspec/rails/version.rb +1 -1
  45. data/lib/rspec/rails/view_rendering.rb +1 -1
  46. data/spec/rspec/rails/mocks/ar_classes.rb +13 -25
  47. data/spec/rspec/rails/mocks/mock_model_spec.rb +6 -0
  48. data/spec/rspec/rails/mocks/stub_model_spec.rb +9 -4
  49. data/spec/rspec/rails/view_rendering_spec.rb +7 -1
  50. data/templates/Gemfile-base +17 -0
  51. metadata +21 -15
  52. data/templates/Gemfile +0 -15
@@ -36,6 +36,18 @@ is what you need to change:
36
36
 
37
37
  ## Controller specs
38
38
 
39
+ ### islation from view templates
40
+
41
+ By default, controller specs do _not_ render view templates. This keeps
42
+ controller specs isolated from the content of views and their requirements.
43
+
44
+ NOTE that the template must exist, but it will not be rendered. This is
45
+ different from rspec-rails-1.x, in which the template didn't need to exist, but
46
+ ActionController makes a number of new decisions in Rails 3 based on the
47
+ existence of the template. To keep the RSpec code free of monkey patches, and
48
+ to keep the rspec user experience simpler, we decided that this would be a fair
49
+ trade-off.
50
+
39
51
  ### `response.should render_template`
40
52
 
41
53
  This needs to move from before the action to after. For example:
@@ -54,3 +66,51 @@ fix releases in RSpec). Part of the philosophy of rspec-rails-2 is to rely on
54
66
  public APIs in Rails as much as possible. In this case, `render_template`
55
67
  delegates directly to Rails' `assert_template`, which only works after the
56
68
  action.
69
+
70
+ ## View specs
71
+
72
+ ### `view.should render_template`
73
+
74
+ Rails changed the way it renders partials, so to set an expectation that a
75
+ partial gets rendered, you need
76
+
77
+ render
78
+ view.should render_template(:partial => "widget/_row")
79
+
80
+ ### stub_template
81
+
82
+ Introduced in rspec-rails-2.2, simulates the presence of view templates on the
83
+ file system. This supports isolation from partials rendered by the vew template
84
+ that is the subject of a view example:
85
+
86
+ stub_template "widgets/_widget.html.erb" => "This Content"
87
+
88
+ ### No more `have_tag`
89
+
90
+ Before Webrat came along, rspec-rails had its own `have_tag` matcher that
91
+ wrapped Rails' `assert_select`. Webrat included a replacement for `have_tag` as
92
+ well as new matchers (`have_selector` and `have_xpath`), all of which rely on
93
+ Nokogiri to do its work, and are far less brittle than RSpec's `have_tag`.
94
+
95
+ Capybara has similar matchers, which will soon be available view specs (they
96
+ are already available in controller specs with `render_views`).
97
+
98
+ Given the brittleness of RSpec's `have_tag` matcher and the presence of new
99
+ Webrat and Capybara matchers that do a better job, `have_tag` was not included
100
+ in rspec-rails-2.
101
+
102
+ ## Mocks, stubs, doubles
103
+
104
+ ### as_new_record
105
+
106
+ Earlier versions of the view generators generated stub_model with `:new_record?
107
+ => true`. That is no longer recognized in rspec-rails-2, so you need to change
108
+ this:
109
+
110
+ stub_model(Widget, :new_record? => true)
111
+
112
+ to this:
113
+
114
+ stub_model(Widget).as_new_record
115
+
116
+ Generators in 2.0.0 final release will do the latter.
@@ -2,8 +2,9 @@ Controller specs live in `spec/controllers` or any example group with
2
2
  `:type => :controller`.
3
3
 
4
4
  A controller spec is an RSpec wrapper for a Rails functional test
5
- (ActionController::TestCase::Behavior). It allows you to simulate a single
6
- http request in each example, and then specify expected outcomes, including:
5
+ ([ActionController::TestCase::Behavior](https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb)).
6
+ It allows you to simulate a single http request in each example, and then
7
+ specify expected outcomes such as:
7
8
 
8
9
  * rendered templates
9
10
  * redirects
@@ -37,7 +37,7 @@ Feature: anonymous controller
37
37
  end
38
38
  """
39
39
  When I run "rspec spec"
40
- Then the output should contain "1 example, 0 failures"
40
+ Then the examples should all pass
41
41
 
42
42
  Scenario: specify error handling in subclass of ApplicationController
43
43
  Given a file named "spec/controllers/application_controller_subclass_spec.rb" with:
@@ -75,4 +75,4 @@ Feature: anonymous controller
75
75
  end
76
76
  """
77
77
  When I run "rspec spec"
78
- Then the output should contain "1 example, 0 failures"
78
+ Then the examples should all pass
@@ -1,6 +1,6 @@
1
1
  Feature: views are stubbed by default
2
2
 
3
- By default, controller specs stub views with template that renders an empty
3
+ By default, controller specs stub views with a template that renders an empty
4
4
  string instead of the views in the app. This allows you specify which view
5
5
  template an action should try to render regardless of whether the template
6
6
  compiles cleanly.
@@ -28,7 +28,7 @@ Feature: views are stubbed by default
28
28
  end
29
29
  """
30
30
  When I run "rspec ./spec"
31
- Then the output should contain "2 examples, 0 failures"
31
+ Then the examples should all pass
32
32
 
33
33
  Scenario: expect template that is not rendered by controller action (fails)
34
34
  Given a file named "spec/controllers/widgets_controller_spec.rb" with:
@@ -1,9 +1,9 @@
1
1
  Feature: render_views
2
2
 
3
3
  You can tell a controller example group to render views with the
4
- `render_views` declaration.
4
+ `render_views` declaration in any individual group, or globally.
5
5
 
6
- Scenario: expect template that exists and is rendered by controller (passes)
6
+ Scenario: render_views directly in a single group
7
7
  Given a file named "spec/controllers/widgets_controller_spec.rb" with:
8
8
  """
9
9
  require "spec_helper"
@@ -11,48 +11,18 @@ Feature: render_views
11
11
  describe WidgetsController do
12
12
  render_views
13
13
 
14
- describe "index" do
15
- it "renders the index template" do
14
+ describe "GET index" do
15
+ it "says 'Listing widgets'" do
16
16
  get :index
17
- response.should contain("Listing widgets")
18
- end
19
-
20
- it "renders the widgets/index template" do
21
- get :index
22
- response.should contain("Listing widgets")
17
+ response.body.should =~ /Listing widgets/m
23
18
  end
24
19
  end
25
20
  end
26
21
  """
27
22
  When I run "rspec spec"
28
- Then the output should contain "2 examples, 0 failures"
23
+ Then the examples should all pass
29
24
 
30
- Scenario: expect template that does not exist and is rendered by controller (fails)
31
- Given a file named "spec/controllers/widgets_controller_spec.rb" with:
32
- """
33
- require "spec_helper"
34
-
35
- describe WidgetsController do
36
- render_views
37
-
38
- before do
39
- def controller.index
40
- render :template => "other"
41
- end
42
- end
43
-
44
- describe "index" do
45
- it "renders the other template" do
46
- get :index
47
- end
48
- end
49
- end
50
- """
51
- When I run "rspec spec"
52
- Then the output should contain "1 example, 1 failure"
53
- And the output should contain "Missing template"
54
-
55
- Scenario: render_views on and off in diff contexts
25
+ Scenario: render_views on and off in nested groups
56
26
  Given a file named "spec/controllers/widgets_controller_spec.rb" with:
57
27
  """
58
28
  require "spec_helper"
@@ -61,19 +31,30 @@ Feature: render_views
61
31
  context "with render_views" do
62
32
  render_views
63
33
 
64
- describe "index" do
34
+ describe "GET index" do
65
35
  it "renders the actual template" do
66
36
  get :index
67
37
  response.body.should =~ /Listing widgets/m
68
38
  end
69
39
  end
40
+
41
+ context "with render_views(false) nested in a group with render_views" do
42
+ render_views false
43
+
44
+ describe "GET index" do
45
+ it "renders the RSpec generated template" do
46
+ get :index
47
+ response.body.should eq("")
48
+ end
49
+ end
50
+ end
70
51
  end
71
52
 
72
53
  context "without render_views" do
73
- describe "index" do
54
+ describe "GET index" do
74
55
  it "renders the RSpec generated template" do
75
56
  get :index
76
- response.body.should == ""
57
+ response.body.should eq("")
77
58
  end
78
59
  end
79
60
  end
@@ -81,26 +62,32 @@ Feature: render_views
81
62
  context "with render_views again" do
82
63
  render_views
83
64
 
84
- describe "index" do
65
+ describe "GET index" do
85
66
  it "renders the actual template" do
86
67
  get :index
87
68
  response.body.should =~ /Listing widgets/m
88
69
  end
89
70
  end
90
71
  end
91
-
92
- context "without render_views again" do
93
- describe "index" do
94
- it "renders the RSpec generated template" do
95
- get :index
96
- response.body.should == ""
97
- end
98
- end
99
- end
100
72
  end
101
73
  """
102
- When I run "rspec spec"
103
- Then the output should contain "4 examples, 0 failures"
74
+ When I run "rspec spec --format documentation"
75
+ Then the output should contain:
76
+ """
77
+ WidgetsController
78
+ with render_views
79
+ GET index
80
+ renders the actual template
81
+ with render_views(false) nested in a group with render_views
82
+ GET index
83
+ renders the RSpec generated template
84
+ without render_views
85
+ GET index
86
+ renders the RSpec generated template
87
+ with render_views again
88
+ GET index
89
+ renders the actual template
90
+ """
104
91
 
105
92
  Scenario: render_views globally
106
93
  Given a file named "spec/support/render_views.rb" with:
@@ -114,19 +101,14 @@ Feature: render_views
114
101
  require "spec_helper"
115
102
 
116
103
  describe WidgetsController do
117
- describe "index" do
104
+ describe "GET index" do
118
105
  it "renders the index template" do
119
106
  get :index
120
- response.should contain("Listing widgets")
121
- end
122
-
123
- it "renders the widgets/index template" do
124
- get :index
125
- response.should contain("Listing widgets")
107
+ response.body.should =~ /Listing widgets/m
126
108
  end
127
109
  end
128
110
  end
129
111
  """
130
112
  When I run "rspec spec"
131
- Then the output should contain "2 examples, 0 failures"
113
+ Then the examples should all pass
132
114
 
@@ -26,7 +26,7 @@ Feature: helper spec
26
26
  end
27
27
  """
28
28
  When I run "rspec spec/helpers/application_helper_spec.rb"
29
- Then the output should contain "1 example, 0 failures"
29
+ Then the examples should all pass
30
30
 
31
31
  Scenario: helper method that accesses an instance variable
32
32
  Given a file named "spec/helpers/application_helper_spec.rb" with:
@@ -51,7 +51,7 @@ Feature: helper spec
51
51
  end
52
52
  """
53
53
  When I run "rspec spec/helpers/application_helper_spec.rb"
54
- Then the output should contain "1 example, 0 failures"
54
+ Then the examples should all pass
55
55
 
56
56
  Scenario: application helper is included in helper object
57
57
  Given a file named "spec/helpers/widgets_helper_spec.rb" with:
@@ -84,4 +84,4 @@ Feature: helper spec
84
84
  end
85
85
  """
86
86
  When I run "rspec spec/helpers/widgets_helper_spec.rb"
87
- Then the output should contain "1 example, 0 failures"
87
+ Then the examples should all pass
@@ -16,7 +16,7 @@ Feature: URL helpers in mailer examples
16
16
  end
17
17
  """
18
18
  When I run "rspec spec"
19
- Then the output should contain "1 example, 0 failures"
19
+ Then the examples should all pass
20
20
 
21
21
  Scenario: using URL helpers without default options
22
22
  Given a file named "config/initializers/mailer_defaults.rb" with:
@@ -35,4 +35,4 @@ Feature: URL helpers in mailer examples
35
35
  end
36
36
  """
37
37
  When I run "rspec spec"
38
- Then the output should contain "1 example, 0 failures"
38
+ Then the examples should all pass
@@ -25,7 +25,7 @@ Feature: be_a_new matcher
25
25
  end
26
26
  """
27
27
  When I run "rspec spec/models/widget_spec.rb"
28
- Then the output should contain "4 examples, 0 failures"
28
+ Then the examples should all pass
29
29
 
30
30
  Scenario: example spec using be_a_new.with
31
31
  Given a file named "spec/models/widget_spec.rb" with:
@@ -67,4 +67,4 @@ Feature: be_a_new matcher
67
67
  end
68
68
  """
69
69
  When I run "rspec spec/models/widget_spec.rb"
70
- Then the output should contain "4 examples, 0 failures"
70
+ Then the examples should all pass
@@ -37,4 +37,4 @@ Feature: redirect_to matcher
37
37
  end
38
38
  """
39
39
  When I run "rspec spec/controllers/widgets_controller_spec.rb"
40
- Then the output should contain "4 examples, 0 failures"
40
+ Then the examples should all pass
@@ -22,4 +22,4 @@ Feature: render_template matcher
22
22
  end
23
23
  """
24
24
  When I run "rspec spec/controllers/gadgets_spec.rb"
25
- Then the output should contain "3 examples, 0 failures"
25
+ Then the examples should all pass
@@ -37,7 +37,7 @@ Feature: mock_model
37
37
  end
38
38
  """
39
39
  When I run "rspec spec/models/car_spec.rb"
40
- Then the output should contain "3 examples, 0 failures"
40
+ Then the examples should all pass
41
41
 
42
42
  Scenario: passing a string that represents an existing constant
43
43
  Given a file named "spec/models/widget_spec.rb" with:
@@ -52,7 +52,7 @@ Feature: mock_model
52
52
  end
53
53
  """
54
54
  When I run "rspec spec/models/widget_spec.rb"
55
- Then the output should contain "1 example, 0 failures"
55
+ Then the examples should all pass
56
56
 
57
57
  Scenario: passing a class that does not extend ActiveModel::Naming
58
58
  Given a file named "spec/models/string_spec.rb" with:
@@ -66,7 +66,7 @@ Feature: mock_model
66
66
  end
67
67
  """
68
68
  When I run "rspec spec/models/string_spec.rb"
69
- Then the output should contain "1 example, 0 failures"
69
+ Then the examples should all pass
70
70
 
71
71
  Scenario: passing an Active Record constant
72
72
  Given a file named "spec/models/widget_spec.rb" with:
@@ -95,7 +95,7 @@ Feature: mock_model
95
95
  end
96
96
  """
97
97
  When I run "rspec spec/models/widget_spec.rb"
98
- Then the output should contain "4 examples, 0 failures"
98
+ Then the examples should all pass
99
99
 
100
100
  Scenario: passing an Active Record constant with method stubs
101
101
  Given a file named "spec/models/widget_spec.rb" with:
@@ -128,4 +128,4 @@ Feature: mock_model
128
128
  end
129
129
  """
130
130
  When I run "rspec spec/models/widget_spec.rb"
131
- Then the output should contain "3 examples, 0 failures"
131
+ Then the examples should all pass
@@ -35,7 +35,7 @@ Feature: stub_model
35
35
  end
36
36
  """
37
37
  When I run "rspec spec/models/widget_spec.rb"
38
- Then the output should contain "4 examples, 0 failures"
38
+ Then the examples should all pass
39
39
 
40
40
  Scenario: passing an Active Record constant with a block of stubs
41
41
  Given a file named "spec/models/widget_spec.rb" with:
@@ -55,4 +55,4 @@ Feature: stub_model
55
55
  end
56
56
  """
57
57
  When I run "rspec spec/models/widget_spec.rb"
58
- Then the output should contain "1 example, 0 failures"
58
+ Then the examples should all pass
@@ -29,4 +29,4 @@ Feature: errors_on
29
29
  end
30
30
  """
31
31
  When I run "rspec spec/models/widget_spec.rb"
32
- Then the output should contain "4 examples, 0 failures"
32
+ Then the examples should all pass
@@ -21,7 +21,7 @@ Feature: transactional examples
21
21
  end
22
22
  """
23
23
  When I run "rspec spec/models/widget_spec.rb"
24
- Then the output should contain "3 examples, 0 failures"
24
+ Then the examples should all pass
25
25
 
26
26
  Scenario: run in transactions (explicit)
27
27
  Given a file named "spec/models/widget_spec.rb" with:
@@ -48,7 +48,7 @@ Feature: transactional examples
48
48
  end
49
49
  """
50
50
  When I run "rspec spec/models/widget_spec.rb"
51
- Then the output should contain "3 examples, 0 failures"
51
+ Then the examples should all pass
52
52
 
53
53
  Scenario: disable transactions (explicit)
54
54
  Given a file named "spec/models/widget_spec.rb" with:
@@ -77,7 +77,7 @@ Feature: transactional examples
77
77
  end
78
78
  """
79
79
  When I run "rspec spec/models/widget_spec.rb"
80
- Then the output should contain "3 examples, 0 failures"
80
+ Then the examples should all pass
81
81
 
82
82
  Scenario: run in transactions with fixture
83
83
  Given a file named "spec/models/thing_spec.rb" with:
@@ -97,7 +97,7 @@ Feature: transactional examples
97
97
  name: MyString
98
98
  """
99
99
  When I run "rspec spec/models/thing_spec.rb"
100
- Then the output should contain "1 example, 0 failures"
100
+ Then the examples should all pass
101
101
 
102
102
 
103
103