rspec-rails 2.14.0.rc1 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04c5822ee12ba5761dfec43b208aeb0d945e70b0
4
- data.tar.gz: 4b06190cf25cd2c4058da8c2b9ba777b3d0d7359
3
+ metadata.gz: 3d8abb1f01a347fd1b2a6ec73a1fa43744b8b721
4
+ data.tar.gz: 2217552c216c853b6cfb550680193da17b324269
5
5
  SHA512:
6
- metadata.gz: 604533fb3bb940d49e396d434633b07ed51e3aa28a7ec16d7c00f38a4bec2722ac123a1658df97125afa827dd05afa52dc89804314ab1ff26f324b105e4945e2
7
- data.tar.gz: 8c4648637f18a46590249f07de896212d4fb08a0913dcd31d48ddbfe543d1cc3f8940543f901c8db9d8c64917ce091ca0fcb9916fa0cd4a014addd2d0ac12113
6
+ metadata.gz: 303482e646eba42a2a8b5eb9a3d6634b769337b3a496db7b40098f0fb99f2dbc9ea05c53f7c12e97dc40dec8802ad69a100e8a26269fd3bd938ed0bac011b345
7
+ data.tar.gz: 8a4c7c39fe7817b538a3fb79c18cfe9852947c542a7f10b426a491968078f7a4afa6411e8c02f3840c38b7816db6204f10be7734d40fe798d5fe2590c8b71a86
@@ -1,3 +1,15 @@
1
+ ### 2.14.0 / 2013-07-06
2
+ [full changelog](http://github.com/rspec/rspec-rails/compare/v2.14.0.rc1...v2.14.0)
3
+
4
+ Bug fixes
5
+
6
+ * Rake tasks do not define methods that might interact with other libraries.
7
+ (Fujimura Daisuke)
8
+ * Reverts fix for out-of-order `let` definitions in controller specs after the
9
+ issue was fixed upstream in rspec-core. (Andy Lindeman)
10
+ * Fixes deprecation warning when using `expect(Model).to have(n).records` with
11
+ Rails 4. (Andy Lindeman)
12
+
1
13
  ### 2.14.0.rc1 / 2013-05-27
2
14
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.13.2...v2.14.0.rc1)
3
15
 
data/README.md CHANGED
@@ -57,7 +57,7 @@ when commands like `rails generate model` and `rails generate controller` are
57
57
  used.
58
58
 
59
59
  You may also invoke invoke RSpec generators independently. For instance,
60
- running `rspec generate rspec:model` will generate a model spec. For more
60
+ running `rails generate rspec:model` will generate a model spec. For more
61
61
  information, see [list of all
62
62
  generators](https://www.relishapp.com/rspec/rspec-rails/docs/generators).
63
63
 
@@ -402,7 +402,7 @@ expect(:get => "/widgets/1/edit").not_to be_routable
402
402
  and subsets of tests (e.g., `rake spec:models`).
403
403
 
404
404
  A full list of the available rake tasks can be seen by running `rake -T | grep
405
- rspec`.
405
+ spec`.
406
406
 
407
407
  ## Customizing `rake` tasks
408
408
 
@@ -0,0 +1,24 @@
1
+ The `rspec:install` generator creates a `.rspec` file, which tells RSpec to
2
+ tell Autotest that you're using RSpec. You'll also need to add the ZenTest and
3
+ autotest-rails gems to your Gemfile:
4
+
5
+ gem "ZenTest", "~> 4.4.2"
6
+ gem "autotest-rails", "~> 4.1.0"
7
+
8
+ If all of the gems in your Gemfile are installed in system gems, you can just
9
+ type
10
+
11
+ autotest
12
+
13
+ If Bundler is managing any gems for you directly (i.e. you've got `:git` or
14
+ `:path` attributes in the Gemfile), however, you may need to run
15
+
16
+ bundle exec autotest
17
+
18
+ If you do, you require Autotest's bundler plugin in a `.autotest` file in the
19
+ project root directory or your home directory:
20
+
21
+ require "autotest/bundler"
22
+
23
+ Now you can just type `autotest`, it should prefix the generated shell command
24
+ with `bundle exec`.
@@ -0,0 +1,24 @@
1
+ RSpec spec are normally generated alongside other application components.
2
+ For instance, `rails generate model` will also generate an RSpec spec file
3
+ for the model.
4
+
5
+ Note that the generators are there to help you get started, but they are no
6
+ substitute for writing your own examples, and they are only guaranteed to work
7
+ out of the box for with Rails' defaults.
8
+
9
+ RSpec generators can also be run independently. For instance,
10
+
11
+ rails generate rspec:model widget
12
+
13
+ will create a new spec file in `spec/models/widget_spec.rb`.
14
+
15
+ The same generator pattern is available for all specs:
16
+
17
+ * scaffold
18
+ * model
19
+ * controller
20
+ * helper
21
+ * view
22
+ * mailer
23
+ * observer
24
+ * integration
@@ -0,0 +1,84 @@
1
+ Install Rails-3
2
+
3
+ $ gem install rails -v "~> 3.0.0"
4
+
5
+ ### Generate an app
6
+
7
+ $ rails new example
8
+ $ cd example
9
+
10
+ ### Add rspec-rails to the Gemfile
11
+
12
+ $ echo 'gem "rspec-rails", :group => [:development, :test]' >> Gemfile
13
+
14
+ ### Install the bundle
15
+
16
+ $ bundle install
17
+
18
+ ### Bootstrap RSpec
19
+
20
+ $ rails generate rspec:install
21
+
22
+ ### Generate a scaffold
23
+
24
+ $ rails generate scaffold Widgets name:string
25
+
26
+ This generates files in the `app` and `spec` directories. The files in the
27
+ `app` directory are generated by Rails, and Rails delegates the generation of
28
+ the files in the `spec` directory to RSpec.
29
+
30
+ ### Run migrations
31
+
32
+ $ rake db:migrate && rake db:test:prepare
33
+
34
+ ### Run RSpec
35
+
36
+ $ rake spec
37
+
38
+ or
39
+
40
+ $ rspec spec --format documentation
41
+
42
+ If all went well, you should see output ending with:
43
+
44
+ 29 examples, 0 failures, 2 pending
45
+
46
+ This output also includes the following controller spec:
47
+
48
+ WidgetsController
49
+ GET index
50
+ assigns all widgets as @widgets
51
+ GET show
52
+ assigns the requested widget as @widget
53
+ GET new
54
+ assigns a new widget as @widget
55
+ GET edit
56
+ assigns the requested widget as @widget
57
+ POST create
58
+ with valid params
59
+ creates a new Widget
60
+ assigns a newly created widget as @widget
61
+ redirects to the created widget
62
+ with invalid params
63
+ assigns a newly created but unsaved widget as @widget
64
+ re-renders the 'new' template
65
+ PUT update
66
+ with valid params
67
+ updates the requested widget
68
+ assigns the requested widget as @widget
69
+ redirects to the widget
70
+ with invalid params
71
+ assigns the widget as @widget
72
+ re-renders the 'edit' template
73
+ DELETE destroy
74
+ destroys the requested widget
75
+ redirects to the widgets list
76
+
77
+ Output like this can help to quickly gain a high level understanding of how an
78
+ object behaves. It also exposes which cases have been specified and which have
79
+ not. Note the balance between the examples for the `create` and `update`
80
+ actions. If the `redirects to the widget` example was missing from one or the
81
+ other, it would be easy to spot.
82
+
83
+ Take a look at the generated `spec/controllers/widgets_controller_spec.rb` to
84
+ get a sense of how to organize your specs to generate output like this.
@@ -0,0 +1,56 @@
1
+ rspec-rails extends Rails' built-in testing framework to support rspec examples
2
+ for requests, controllers, models, views, helpers, mailers and routing.
3
+
4
+ ## Rails-3
5
+
6
+ rspec-rails-2 supports rails-3.0.0 and later. For earlier versions of Rails,
7
+ you need [rspec-rails-1.3](http://rspec.info).
8
+
9
+ ## Install
10
+
11
+ gem install rspec-rails
12
+
13
+ This installs the following gems:
14
+
15
+ rspec
16
+ rspec-core
17
+ rspec-expectations
18
+ rspec-mocks
19
+ rspec-rails
20
+
21
+ ## Configure
22
+
23
+ Add rspec-rails to the :test and :development groups in the Gemfile:
24
+
25
+ group :test, :development do
26
+ gem "rspec-rails", "~> 2.4"
27
+ end
28
+
29
+ It needs to be in the :development group to expose generators and rake tasks
30
+ without having to type RAILS_ENV=test.
31
+
32
+ Now you can run:
33
+
34
+ script/rails generate rspec:install
35
+
36
+ This adds the spec directory and some skeleton files, including a .rspec
37
+ file.
38
+
39
+ ## Webrat and Capybara
40
+
41
+ You can choose between webrat or capybara for simulating a browser, automating
42
+ a browser, or setting expectations using the matchers they supply. Just add
43
+ your preference to the Gemfile:
44
+
45
+ gem "webrat"
46
+ gem "capybara"
47
+
48
+ ## Issues
49
+
50
+ The documentation for rspec-rails is a work in progress. We'll be adding
51
+ Cucumber features over time, and clarifying existing ones. If you have
52
+ specific features you'd like to see added, find the existing documentation
53
+ incomplete or confusing, or, better yet, wish to write a missing Cucumber
54
+ feature yourself, please [submit an
55
+ issue](http://github.com/rspec/rspec-rails/issues) or a [pull
56
+ request](http://github.com/rspec/rspec-rails).
@@ -0,0 +1,4 @@
1
+ rails version | rspec-rails version
2
+ 2.3 | 1.3.4
3
+ 3.0 | >= 2.0
4
+ 3.1 | >= 2.6
@@ -0,0 +1,84 @@
1
+ When you run `rails generate rspec:install`, the `spec/spec_helper.rb` file
2
+ includes the following configuration:
3
+
4
+ RSpec.configure do |config|
5
+ config.use_transactional_fixtures = true
6
+ end
7
+
8
+ The name of this setting is a bit misleading. What it really means in Rails
9
+ is "run every test method within a transaction." In the context of rspec-rails,
10
+ it means "run every example within a transaction."
11
+
12
+ The idea is to start each example with a clean database, create whatever data
13
+ is necessary for that example, and then remove that data by simply rolling back
14
+ the transaction at the end of the example.
15
+
16
+ ### Disabling transactions
17
+
18
+ If you prefer to manage the data yourself, or using another tool like
19
+ [database_cleaner](https://github.com/bmabey/database_cleaner) to do it for you,
20
+ simply tell RSpec to tell Rails not to manage transactions:
21
+
22
+ RSpec.configure do |config|
23
+ config.use_transactional_fixtures = false
24
+ end
25
+
26
+ ### Data created in `before(:each)` are rolled back
27
+
28
+ Any data you create in a `before(:each)` hook will be rolled back at the end of
29
+ the example. This is a good thing because it means that each example is
30
+ isolated from state that would otherwise be left around by the examples that
31
+ already ran. For example:
32
+
33
+ describe Widget do
34
+ before(:each) do
35
+ @widget = Widget.create
36
+ end
37
+
38
+ it "does something" do
39
+ expect(@widget).to do_something
40
+ end
41
+
42
+ it "does something else" do
43
+ expect(@widget).to do_something_else
44
+ end
45
+ end
46
+
47
+ The `@widget` is recreated in each of the two examples above, so each example
48
+ has a different object, _and_ the underlying data is rolled back so the data
49
+ backing the `@widget` in each example is new.
50
+
51
+ ### Data created in `before(:all)` are _not_ rolled back
52
+
53
+ `before(:all)` hooks are invoked before the transaction is opened. You can use
54
+ this to speed things up by creating data once before any example in a group is
55
+ run, however, this introduces a number of complications and you should only do
56
+ this if you have a firm grasp of the implications. Here are a couple of
57
+ guidelines:
58
+
59
+ 1. Be sure to clean up any data in an `after(:all)` hook:
60
+
61
+ before(:all) do
62
+ @widget = Widget.create!
63
+ end
64
+
65
+ after(:all) do
66
+ @widget.destroy
67
+ end
68
+
69
+ If you don't do that, you'll leave data lying around that will eventually
70
+ interfere with other examples.
71
+
72
+ 2. Reload the object in a `before(:each)` hook.
73
+
74
+ before(:all) do
75
+ @widget = Widget.create!
76
+ end
77
+
78
+ before(:each) do
79
+ @widget.reload
80
+ end
81
+
82
+ Even though database updates in each example will be rolled back, the
83
+ object won't _know_ about those rollbacks so the object and its backing
84
+ data can easily get out of sync.
@@ -0,0 +1,121 @@
1
+ # Upgrading from rspec-rails-1.x to rspec-rails-2.
2
+
3
+ This is a work in progress. Please submit errata, missing steps, or patches to
4
+ the [rspec-rails issue tracker](https://github.com/rspec/rspec-rails/issues).
5
+
6
+ ## Rake tasks
7
+
8
+ Delete lib/tasks/rspec.rake, if present. Rake tasks now live in the rspec-rails
9
+ gem.
10
+
11
+ ## `spec_helper.rb`
12
+
13
+ There were a few changes to the generated `spec/spec_helper.rb` file. We
14
+ recommend the following:
15
+
16
+ 1. set aside a copy of your existing `spec/spec_helper.rb` file.
17
+ 2. run `rails generate rspec:install`
18
+ 3. copy any customizations from your old spec_helper to the new one
19
+
20
+ If you prefer to make the changes manually in the existing spec_helper, here
21
+ is what you need to change:
22
+
23
+ # rspec-1
24
+ require 'spec/autorun'
25
+
26
+ Spec::Runner.configure do |config|
27
+ ...
28
+ end
29
+
30
+ # rspec-2
31
+ require 'rspec/rails'
32
+
33
+ RSpec.configure do |config|
34
+ ...
35
+ end
36
+
37
+ ## Controller specs
38
+
39
+ ### isolation 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
+
51
+ ### `response.should render_template`
52
+
53
+ This needs to move from before the action to after. For example:
54
+
55
+ # rspec-rails-1
56
+ controller.should render_template("edit")
57
+ get :edit, :id => "37"
58
+
59
+ # rspec-rails-2
60
+ get :edit, :id => "37"
61
+ response.should render_template("edit")
62
+
63
+ # rspec-rails-2 with expect syntax
64
+ get :edit, :id => "37"
65
+ expect(response).to render_template("edit")
66
+
67
+ rspec-1 had to monkey patch Rails to get render_template to work before the
68
+ action, and this broke a couple of times with Rails releases (requiring urgent
69
+ fix releases in RSpec). Part of the philosophy of rspec-rails-2 is to rely on
70
+ public APIs in Rails as much as possible. In this case, `render_template`
71
+ delegates directly to Rails' `assert_template`, which only works after the
72
+ action.
73
+
74
+ ## View specs
75
+
76
+ ### `view.should render_template`
77
+
78
+ Rails changed the way it renders partials, so to set an expectation that a
79
+ partial gets rendered, you need
80
+
81
+ render
82
+ view.should render_template(:partial => "widget/_row")
83
+
84
+ ### stub_template
85
+
86
+ Introduced in rspec-rails-2.2, simulates the presence of view templates on the
87
+ file system. This supports isolation from partials rendered by the vew template
88
+ that is the subject of a view example:
89
+
90
+ stub_template "widgets/_widget.html.erb" => "This Content"
91
+
92
+ ### No more `have_tag` or `have_text`
93
+
94
+ Before Webrat came along, rspec-rails had its own `have_tag` and `have_text`
95
+ matchers that wrapped Rails' `assert_select`. Webrat included replacements for
96
+ these methods, as well as new matchers (`have_selector` and `have_xpath`), all
97
+ of which rely on Nokogiri to do its work, and are far less brittle than RSpec's
98
+ `have_tag`.
99
+
100
+ Capybara has similar matchers, which will soon be available view specs (they
101
+ are already available in controller specs with `render_views`).
102
+
103
+ Given the brittleness of RSpec's `have_tag` and `have_text` matchers and the
104
+ presence of new Webrat and Capybara matchers that do a better job, `have_tag`
105
+ and `have_text` were not included in rspec-rails-2.
106
+
107
+ ## Mocks, stubs, doubles
108
+
109
+ ### as_new_record
110
+
111
+ Earlier versions of the view generators generated stub_model with `:new_record?
112
+ => true`. That is no longer recognized in rspec-rails-2, so you need to change
113
+ this:
114
+
115
+ stub_model(Widget, :new_record? => true)
116
+
117
+ to this:
118
+
119
+ stub_model(Widget).as_new_record
120
+
121
+ Generators in 2.0.0 final release will do the latter.