rspec-rails 2.5.0 → 2.6.0.rc2
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.
- data/.gitignore +9 -4
- data/.travis.yml +11 -0
- data/README_DEV.md +43 -0
- data/Rakefile +54 -27
- data/Thorfile +6 -21
- data/features/Autotest.md +7 -0
- data/features/Changelog.md +17 -2
- data/features/Upgrade.md +13 -12
- data/features/controller_specs/README.md +18 -10
- data/features/controller_specs/anonymous_controller.feature +5 -5
- data/features/controller_specs/controller_spec.feature +1 -1
- data/features/controller_specs/isolation_from_views.feature +2 -2
- data/features/controller_specs/render_views.feature +3 -3
- data/features/helper_specs/helper_spec.feature +3 -3
- data/features/mailer_specs/url_helpers.feature +2 -2
- data/features/matchers/new_record_matcher.feature +2 -2
- data/features/matchers/redirect_to_matcher.feature +1 -1
- data/features/matchers/render_template_matcher.feature +1 -1
- data/features/mocks/mock_model.feature +21 -5
- data/features/mocks/stub_model.feature +2 -2
- data/features/model_specs/errors_on.feature +1 -1
- data/features/model_specs/transactional_examples.feature +10 -5
- data/features/routing_specs/README.md +2 -1
- data/features/routing_specs/be_routable_matcher.feature +5 -5
- data/features/routing_specs/named_routes.feature +1 -1
- data/features/routing_specs/route_to_matcher.feature +28 -8
- data/features/step_definitions/additional_cli_steps.rb +1 -1
- data/features/support/env.rb +7 -18
- data/features/view_specs/inferred_controller_path.feature +3 -3
- data/features/view_specs/stub_template.feature +2 -2
- data/features/view_specs/view_spec.feature +8 -8
- data/gemfiles/base.rb +45 -0
- data/gemfiles/rails-3-0-stable +7 -0
- data/gemfiles/rails-3.0.0 +5 -0
- data/gemfiles/rails-3.0.1 +5 -0
- data/gemfiles/rails-3.0.2 +5 -0
- data/gemfiles/rails-3.0.3 +5 -0
- data/gemfiles/rails-3.0.4 +5 -0
- data/gemfiles/rails-3.0.5 +5 -0
- data/gemfiles/rails-3.0.6 +5 -0
- data/gemfiles/rails-master +7 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +20 -2
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +23 -23
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +7 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -5
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/rspec/rails/example/controller_example_group.rb +9 -1
- data/lib/rspec/rails/example/routing_example_group.rb +1 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +23 -2
- data/lib/rspec/rails/mocks.rb +3 -0
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/version.rb +1 -1
- data/rspec-rails.gemspec +5 -36
- data/spec/autotest/rails_rspec2_spec.rb +2 -7
- data/spec/rspec/rails/example/controller_example_group_spec.rb +25 -0
- data/spec/rspec/rails/matchers/route_to_spec.rb +15 -0
- data/spec/rspec/rails/mocks/ar_classes.rb +5 -2
- data/spec/rspec/rails/view_rendering_spec.rb +0 -6
- data/templates/generate_stuff.rb +2 -1
- data/templates/run_specs.rb +2 -2
- metadata +54 -77
- data/Gemfile-3-0-stable +0 -6
- data/Gemfile-3.0.0 +0 -3
- data/Gemfile-3.0.3 +0 -3
- data/Gemfile-base +0 -38
- data/Gemfile-master +0 -5
- data/specs.watchr +0 -59
- data/templates/Gemfile-base +0 -17
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README_DEV.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Information for rspec-rails developers
|
2
|
+
|
3
|
+
rspec-rails lives in a complicated ecosystem. We need to run it against
|
4
|
+
multiple versions of rails and multiple versions of Ruby as well. There are
|
5
|
+
several tools already available to manage running against multiple versions of
|
6
|
+
Ruby (e.g. rvm), and there are even some multi-rails tools (e.g. multi-rails)
|
7
|
+
but we haven't found one that does exactly what we need here, so we've rolled
|
8
|
+
our own.
|
9
|
+
|
10
|
+
## The short version
|
11
|
+
|
12
|
+
thor rails:use 3.0.6
|
13
|
+
rake
|
14
|
+
|
15
|
+
## The long version
|
16
|
+
|
17
|
+
### thor rails:use
|
18
|
+
|
19
|
+
The `thor rails:use` task accepts any released version of rails, or either the
|
20
|
+
3-0-stable or master branches.
|
21
|
+
|
22
|
+
thor rails:use master
|
23
|
+
thor rails:use 3-0-stable
|
24
|
+
thor rails:use 3.0.6
|
25
|
+
thor rails:use 3.0.5
|
26
|
+
thor rails:use 3.0.4
|
27
|
+
thor rails:use 3.0.3
|
28
|
+
thor rails:use 3.0.2
|
29
|
+
thor rails:use 3.0.1
|
30
|
+
thor rails:use 3.0.0
|
31
|
+
|
32
|
+
It then does several things:
|
33
|
+
|
34
|
+
* generates a .gemfile file with the version listed. This is used internally by
|
35
|
+
assorted rake tasks.
|
36
|
+
* installs the bundle using the appropriate file in the gemfiles directory
|
37
|
+
** this includes binstubs, which are stored in ./gemfiles/bin
|
38
|
+
* symlinks the gemfiles/bin directory to ./bin (in the project root) to support
|
39
|
+
running bin/rspec from the project root
|
40
|
+
|
41
|
+
At any time, if you want to change rails versions, run `thor rails:use` with a
|
42
|
+
new version number. To play it safe, you probably want to also run `rake
|
43
|
+
clobber` to delete all the code generated by the previous rails version.
|
data/Rakefile
CHANGED
@@ -1,14 +1,34 @@
|
|
1
|
-
unless File.exist?(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
unless File.exist?("./.gemfile")
|
2
|
+
warn <<-MESSAGE
|
3
|
+
=============================================================================
|
4
|
+
You must set the version of rails you want to run against. The simplest way
|
5
|
+
to accomplish this is to install thor (if you don't already have it) and run:
|
6
|
+
|
7
|
+
thor rails:use 3.0.6
|
8
|
+
|
9
|
+
You can use any of the following versions/branches:
|
10
|
+
|
11
|
+
3.0.0 .. 3.0.6
|
12
|
+
master
|
13
|
+
3-0-stable
|
14
|
+
|
15
|
+
See the README_DEV.md file for more information.
|
16
|
+
=============================================================================
|
17
|
+
|
10
18
|
MESSAGE
|
19
|
+
exit 1
|
11
20
|
end
|
21
|
+
|
22
|
+
require 'pathname'
|
23
|
+
ENV["BUNDLE_GEMFILE"] ||= begin
|
24
|
+
version = if File.exist?("./.gemfile")
|
25
|
+
File.read("./.gemfile").chomp
|
26
|
+
else
|
27
|
+
"rails-3.0.6"
|
28
|
+
end
|
29
|
+
File.expand_path("../gemfiles/#{version}", __FILE__)
|
30
|
+
end
|
31
|
+
puts "Using gemfile: #{ENV["BUNDLE_GEMFILE"].gsub(Pathname.new(__FILE__).dirname.to_s,'').sub(/^\//,'')}"
|
12
32
|
require "bundler"
|
13
33
|
Bundler.setup
|
14
34
|
Bundler::GemHelper.install_tasks
|
@@ -19,8 +39,27 @@ require 'yaml'
|
|
19
39
|
require 'rake/rdoctask'
|
20
40
|
require 'rspec'
|
21
41
|
require 'rspec/core/rake_task'
|
22
|
-
require 'cucumber/rake/task'
|
23
42
|
|
43
|
+
begin
|
44
|
+
require 'cucumber/rake/task'
|
45
|
+
|
46
|
+
Cucumber::Rake::Task.new(:cucumber)
|
47
|
+
|
48
|
+
namespace :cucumber do
|
49
|
+
desc "Run cucumber features using rcov"
|
50
|
+
Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
|
51
|
+
t.cucumber_opts = %w{--format progress}
|
52
|
+
t.rcov = true
|
53
|
+
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
|
54
|
+
t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
rescue LoadError
|
58
|
+
puts "unable to load cucumber, some tasks unavailable"
|
59
|
+
task :cucumber do
|
60
|
+
# no-op
|
61
|
+
end
|
62
|
+
end
|
24
63
|
task :cleanup_rcov_files do
|
25
64
|
rm_rf 'coverage.data'
|
26
65
|
end
|
@@ -30,7 +69,6 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
30
69
|
t.rspec_opts = %w[--color]
|
31
70
|
end
|
32
71
|
|
33
|
-
Cucumber::Rake::Task.new(:cucumber)
|
34
72
|
|
35
73
|
namespace :spec do
|
36
74
|
desc "Run all examples using rcov"
|
@@ -41,29 +79,20 @@ namespace :spec do
|
|
41
79
|
end
|
42
80
|
end
|
43
81
|
|
44
|
-
namespace :cucumber do
|
45
|
-
desc "Run cucumber features using rcov"
|
46
|
-
Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
|
47
|
-
t.cucumber_opts = %w{--format progress}
|
48
|
-
t.rcov = true
|
49
|
-
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
|
50
|
-
t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
82
|
namespace :generate do
|
55
83
|
desc "generate a fresh app with rspec installed"
|
56
84
|
task :app do |t|
|
57
85
|
unless File.directory?('./tmp/example_app')
|
58
|
-
sh "
|
59
|
-
|
60
|
-
|
86
|
+
sh "bin/rails new ./tmp/example_app"
|
87
|
+
bindir = File.expand_path("gemfiles/bin")
|
88
|
+
Dir.chdir("./tmp/example_app") do
|
89
|
+
sh "ln -s #{bindir}"
|
90
|
+
end
|
61
91
|
end
|
62
92
|
end
|
63
93
|
|
64
94
|
desc "generate a bunch of stuff with generators"
|
65
95
|
task :stuff do
|
66
|
-
in_example_app "bundle install"
|
67
96
|
in_example_app "rake rails:template LOCATION='../../templates/generate_stuff.rb'"
|
68
97
|
end
|
69
98
|
end
|
@@ -114,5 +143,3 @@ task :relish, :version do |t, args|
|
|
114
143
|
end
|
115
144
|
|
116
145
|
task :default => [:spec, "clobber:app", "generate:app", "generate:stuff", :smoke, :cucumber]
|
117
|
-
|
118
|
-
|
data/Thorfile
CHANGED
@@ -1,25 +1,10 @@
|
|
1
1
|
class Rails < Thor
|
2
|
-
desc "
|
3
|
-
def checkout(version)
|
4
|
-
puts "***** checking out rails at #{version} ..."
|
5
|
-
Dir.chdir("vendor/rails") do
|
6
|
-
`git checkout #{version}`
|
7
|
-
`rm Gemfile.lock` if File.exist?('Gemfile.lock')
|
8
|
-
puts `bundle show`
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
desc "fetch", "update vendor/rails"
|
13
|
-
def fetch
|
14
|
-
Dir.chdir("vendor/rails") do
|
15
|
-
`git fetch`
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
desc "use VERSION", "copies the appropriate Gemfile to Gemfile"
|
2
|
+
desc "use VERSION", "installs the bundle using gemfiles/rails-VERSION"
|
20
3
|
def use(version)
|
21
|
-
|
22
|
-
`
|
23
|
-
|
4
|
+
gemfile = "--gemfile gemfiles/rails-#{version}"
|
5
|
+
say `bundle install #{gemfile} --binstubs`
|
6
|
+
say `bundle #{gemfile} update rails` unless version =~ /^\d\.\d\.\d$/
|
7
|
+
say `ln -s gemfiles/bin` unless File.exist?('bin')
|
8
|
+
`echo rails-#{version} > ./.gemfile`
|
24
9
|
end
|
25
10
|
end
|
data/features/Autotest.md
CHANGED
@@ -15,3 +15,10 @@ If Bundler is managing any gems for you directly (i.e. you've got `:git` or
|
|
15
15
|
|
16
16
|
bundle exec autotest
|
17
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`.
|
data/features/Changelog.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
### 2.6.0.rc2 / 2011-04-18
|
2
|
+
|
3
|
+
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.5.0...v2.6.1.rc2)
|
4
|
+
|
5
|
+
* Enhancments
|
6
|
+
* rails 3 shortcuts for routing specs (Joe Fiorini)
|
7
|
+
* support nested resources in generators (Tim McEwan)
|
8
|
+
* require 'rspec/rails/mocks' to use `mock_model` without requiring the whole
|
9
|
+
rails framework
|
10
|
+
|
11
|
+
* Bug fixes
|
12
|
+
* fix typo in "rake spec:statsetup" (Curtis Schofield)
|
13
|
+
* expose named routes in anonymous controller specs (Andy Lindeman)
|
14
|
+
* error when generating namespaced scaffold resources (Andy Lindeman)
|
15
|
+
|
1
16
|
### 2.5.0 / 2011-02-05
|
2
17
|
|
3
18
|
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.4.1...v2.5.0)
|
@@ -5,11 +20,11 @@
|
|
5
20
|
* Enhancements
|
6
21
|
* use index_helper instead of table_name when generating specs (Reza
|
7
22
|
Primardiansyah)
|
8
|
-
|
23
|
+
|
9
24
|
* Bug fixes
|
10
25
|
* fixed bug in which `render_views` in a nested group set the value in its
|
11
26
|
parent group.
|
12
|
-
* only include MailerExampleGroup when it is
|
27
|
+
* only include MailerExampleGroup when it is defined (Steve Sloan)
|
13
28
|
* mock_model.as_null_object.attribute.blank? returns false (Randy Schmidt)
|
14
29
|
* fix typo in request specs (Paco Guzman)
|
15
30
|
|
data/features/Upgrade.md
CHANGED
@@ -14,7 +14,7 @@ There were a few changes to the generated `spec/spec_helper.rb` file. We
|
|
14
14
|
recommend the following:
|
15
15
|
|
16
16
|
1. set aside a copy of your existing `spec/spec_helper.rb` file.
|
17
|
-
2. run `rails generate
|
17
|
+
2. run `rails generate rspec:install`
|
18
18
|
3. copy any customizations from your old spec_helper to the new one
|
19
19
|
|
20
20
|
If you prefer to make the changes manually in the existing spec_helper, here
|
@@ -28,7 +28,7 @@ is what you need to change:
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# rspec-2
|
31
|
-
require 'rspec/
|
31
|
+
require 'rspec/rails'
|
32
32
|
|
33
33
|
RSpec.configure do |config|
|
34
34
|
...
|
@@ -72,7 +72,7 @@ action.
|
|
72
72
|
### `view.should render_template`
|
73
73
|
|
74
74
|
Rails changed the way it renders partials, so to set an expectation that a
|
75
|
-
partial gets rendered, you need
|
75
|
+
partial gets rendered, you need
|
76
76
|
|
77
77
|
render
|
78
78
|
view.should render_template(:partial => "widget/_row")
|
@@ -85,19 +85,20 @@ that is the subject of a view example:
|
|
85
85
|
|
86
86
|
stub_template "widgets/_widget.html.erb" => "This Content"
|
87
87
|
|
88
|
-
### No more `have_tag`
|
88
|
+
### No more `have_tag` or `have_text`
|
89
89
|
|
90
|
-
Before Webrat came along, rspec-rails had its own `have_tag`
|
91
|
-
wrapped Rails' `assert_select`. Webrat included
|
92
|
-
well as new matchers (`have_selector` and `have_xpath`), all
|
93
|
-
Nokogiri to do its work, and are far less brittle than RSpec's
|
90
|
+
Before Webrat came along, rspec-rails had its own `have_tag` and `have_text`
|
91
|
+
matchers that wrapped Rails' `assert_select`. Webrat included replacements for
|
92
|
+
these methods, as well as new matchers (`have_selector` and `have_xpath`), all
|
93
|
+
of which rely on Nokogiri to do its work, and are far less brittle than RSpec's
|
94
|
+
`have_tag`.
|
94
95
|
|
95
96
|
Capybara has similar matchers, which will soon be available view specs (they
|
96
97
|
are already available in controller specs with `render_views`).
|
97
98
|
|
98
|
-
Given the brittleness of RSpec's `have_tag`
|
99
|
-
Webrat and Capybara matchers that do a better job, `have_tag`
|
100
|
-
in rspec-rails-2.
|
99
|
+
Given the brittleness of RSpec's `have_tag` and `have_text` matchers and the
|
100
|
+
presence of new Webrat and Capybara matchers that do a better job, `have_tag`
|
101
|
+
and `have_text` were not included in rspec-rails-2.
|
101
102
|
|
102
103
|
## Mocks, stubs, doubles
|
103
104
|
|
@@ -106,7 +107,7 @@ in rspec-rails-2.
|
|
106
107
|
Earlier versions of the view generators generated stub_model with `:new_record?
|
107
108
|
=> true`. That is no longer recognized in rspec-rails-2, so you need to change
|
108
109
|
this:
|
109
|
-
|
110
|
+
|
110
111
|
stub_model(Widget, :new_record? => true)
|
111
112
|
|
112
113
|
to this:
|
@@ -21,16 +21,24 @@ To specify outcomes, you can use:
|
|
21
21
|
* `response.should redirect_to (wraps assert_redirected_to)`
|
22
22
|
* `assigns(:widget).should be_a_new(Widget)`
|
23
23
|
|
24
|
-
##
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
## Examples
|
25
|
+
|
26
|
+
describe TeamsController do
|
27
|
+
describe "GET index" do
|
28
|
+
it "assigns @teams" do
|
29
|
+
team = Team.create
|
30
|
+
get :index
|
31
|
+
assigns(:teams).should eq([team])
|
32
|
+
end
|
33
|
+
|
34
|
+
it "renders the index template" do
|
35
|
+
get :index
|
36
|
+
response.should render_template("index")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
## Views
|
34
42
|
|
35
43
|
* by default, views are not rendered. See
|
36
44
|
[views are stubbed by default](controller-specs/views-are-stubbed-by-default) and
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Feature: anonymous controller
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Use the `controller` method to define an anonymous controller derived from
|
4
|
+
ApplicationController, or any other base controller. This is useful for
|
5
|
+
specifying behavior like global error handling.
|
6
6
|
|
7
7
|
Scenario: specify error handling in ApplicationController
|
8
8
|
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
@@ -36,7 +36,7 @@ Feature: anonymous controller
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
"""
|
39
|
-
When I run
|
39
|
+
When I run `rspec spec`
|
40
40
|
Then the examples should all pass
|
41
41
|
|
42
42
|
Scenario: specify error handling in subclass of ApplicationController
|
@@ -74,5 +74,5 @@ Feature: anonymous controller
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
"""
|
77
|
-
When I run
|
77
|
+
When I run `rspec spec`
|
78
78
|
Then the examples should all pass
|
@@ -27,7 +27,7 @@ Feature: views are stubbed by default
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
"""
|
30
|
-
When I run
|
30
|
+
When I run `rspec spec`
|
31
31
|
Then the examples should all pass
|
32
32
|
|
33
33
|
Scenario: expect template that is not rendered by controller action (fails)
|
@@ -44,6 +44,6 @@ Feature: views are stubbed by default
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
"""
|
47
|
-
When I run
|
47
|
+
When I run `rspec spec`
|
48
48
|
Then the output should contain "1 example, 1 failure"
|
49
49
|
|
@@ -19,7 +19,7 @@ Feature: render_views
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
"""
|
22
|
-
When I run
|
22
|
+
When I run `rspec spec`
|
23
23
|
Then the examples should all pass
|
24
24
|
|
25
25
|
Scenario: render_views on and off in nested groups
|
@@ -71,7 +71,7 @@ Feature: render_views
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
"""
|
74
|
-
When I run
|
74
|
+
When I run `rspec spec --format documentation`
|
75
75
|
Then the output should contain:
|
76
76
|
"""
|
77
77
|
WidgetsController
|
@@ -109,6 +109,6 @@ Feature: render_views
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
"""
|
112
|
-
When I run
|
112
|
+
When I run `rspec spec`
|
113
113
|
Then the examples should all pass
|
114
114
|
|