rspec-rails 2.5.0 → 2.6.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.
- data/.gitignore +10 -5
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/README.md +2 -0
- data/README_DEV.md +43 -0
- data/Rakefile +72 -31
- data/Thorfile +33 -18
- data/features/.nav +2 -0
- data/features/Autotest.md +7 -0
- data/features/Changelog.md +26 -2
- data/features/Generators.md +1 -1
- data/features/GettingStarted.md +45 -1
- 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 -2
- data/features/controller_specs/isolation_from_views.feature +49 -3
- 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 +1 -43
- data/features/matchers/redirect_to_matcher.feature +3 -3
- data/features/matchers/render_template_matcher.feature +12 -9
- 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/request_specs/request_spec.feature +49 -0
- 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 -19
- 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 +16 -35
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/base.rb +58 -0
- data/gemfiles/rails-3-0-stable +6 -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-3.0.7 +5 -0
- data/gemfiles/rails-3.1.0.beta1 +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 +86 -54
- 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 +12 -22
- data/lib/rspec/rails/example/helper_example_group.rb +0 -5
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -9
- data/lib/rspec/rails/example/request_example_group.rb +0 -25
- data/lib/rspec/rails/example/routing_example_group.rb +1 -0
- data/lib/rspec/rails/example/view_example_group.rb +7 -6
- 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/vendor/capybara.rb +29 -0
- data/lib/rspec/rails/vendor/webrat.rb +33 -0
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +24 -8
- data/lib/rspec/rails.rb +2 -2
- 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/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +9 -0
- data/templates/generate_stuff.rb +9 -1
- data/templates/run_specs.rb +2 -2
- metadata +44 -65
- 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/lib/rspec/rails/browser_simulators.rb +0 -30
- data/specs.watchr +0 -59
- data/templates/Gemfile-base +0 -17
data/.gitignore
CHANGED
data/.rspec
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/README.md
CHANGED
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,26 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
end
|
|
1
|
+
require 'pathname'
|
|
2
|
+
ENV["BUNDLE_GEMFILE"] ||= begin
|
|
3
|
+
version = if File.exist?("./.gemfile")
|
|
4
|
+
File.read("./.gemfile").chomp
|
|
5
|
+
else
|
|
6
|
+
"rails-3.0.7"
|
|
7
|
+
end
|
|
8
|
+
File.expand_path("../gemfiles/#{version}", __FILE__)
|
|
9
|
+
end
|
|
10
|
+
puts "Using gemfile: #{ENV["BUNDLE_GEMFILE"].gsub(Pathname.new(__FILE__).dirname.to_s,'').sub(/^\//,'')}"
|
|
12
11
|
require "bundler"
|
|
13
|
-
|
|
12
|
+
begin
|
|
13
|
+
Bundler.setup
|
|
14
|
+
rescue
|
|
15
|
+
if ENV["CI"]
|
|
16
|
+
sh "bundle install"
|
|
17
|
+
Bundler.setup
|
|
18
|
+
else
|
|
19
|
+
raise "You need to install a bundle first. Try 'thor gemfile:use 3.0.7'"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
14
22
|
Bundler::GemHelper.install_tasks
|
|
15
23
|
|
|
24
|
+
task :build => :raise_if_psych_is_defined
|
|
25
|
+
|
|
26
|
+
task :raise_if_psych_is_defined do
|
|
27
|
+
if defined?(Psych)
|
|
28
|
+
raise <<-MSG
|
|
29
|
+
===============================================================================
|
|
30
|
+
Gems compiled in Ruby environments with Psych loaded are incompatible with Ruby
|
|
31
|
+
environments that don't have Psych loaded. Try building this gem in Ruby 1.8.7
|
|
32
|
+
instead.
|
|
33
|
+
===============================================================================
|
|
34
|
+
MSG
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
16
38
|
require 'rake'
|
|
17
39
|
require 'yaml'
|
|
18
40
|
|
|
19
|
-
require 'rake/rdoctask'
|
|
20
41
|
require 'rspec'
|
|
21
42
|
require 'rspec/core/rake_task'
|
|
22
|
-
require 'cucumber/rake/task'
|
|
23
43
|
|
|
44
|
+
begin
|
|
45
|
+
require 'cucumber/rake/task'
|
|
46
|
+
|
|
47
|
+
Cucumber::Rake::Task.new(:cucumber)
|
|
48
|
+
|
|
49
|
+
namespace :cucumber do
|
|
50
|
+
desc "Run cucumber features using rcov"
|
|
51
|
+
Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
|
|
52
|
+
t.cucumber_opts = %w{--format progress}
|
|
53
|
+
t.rcov = true
|
|
54
|
+
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
|
|
55
|
+
t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
rescue LoadError
|
|
59
|
+
puts "unable to load cucumber, some tasks unavailable"
|
|
60
|
+
task :cucumber do
|
|
61
|
+
# no-op
|
|
62
|
+
end
|
|
63
|
+
end
|
|
24
64
|
task :cleanup_rcov_files do
|
|
25
65
|
rm_rf 'coverage.data'
|
|
26
66
|
end
|
|
@@ -30,7 +70,6 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
|
30
70
|
t.rspec_opts = %w[--color]
|
|
31
71
|
end
|
|
32
72
|
|
|
33
|
-
Cucumber::Rake::Task.new(:cucumber)
|
|
34
73
|
|
|
35
74
|
namespace :spec do
|
|
36
75
|
desc "Run all examples using rcov"
|
|
@@ -41,29 +80,33 @@ namespace :spec do
|
|
|
41
80
|
end
|
|
42
81
|
end
|
|
43
82
|
|
|
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
83
|
namespace :generate do
|
|
55
84
|
desc "generate a fresh app with rspec installed"
|
|
56
85
|
task :app do |t|
|
|
57
86
|
unless File.directory?('./tmp/example_app')
|
|
58
|
-
sh "
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
sh "rails new ./tmp/example_app --skip-javascript --skip-gemfile --skip-git"
|
|
88
|
+
bindir = File.expand_path("gemfiles/bin")
|
|
89
|
+
if test ?d, bindir
|
|
90
|
+
Dir.chdir("./tmp/example_app") do
|
|
91
|
+
sh "rm -rf test"
|
|
92
|
+
sh "ln -s #{bindir}"
|
|
93
|
+
application_filename = "config/application.rb"
|
|
94
|
+
application_file = File.read(application_filename)
|
|
95
|
+
sh "rm #{application_filename}"
|
|
96
|
+
puts "rewrite #{application_filename} with config.assets.enabled = false"
|
|
97
|
+
File.open(application_filename, "w") do |f|
|
|
98
|
+
f.write application_file.gsub("config.assets.enabled = true","config.assets.enabled = false")
|
|
99
|
+
end
|
|
100
|
+
"config/initializers/wrap_parameters.rb".tap do |f|
|
|
101
|
+
sh "rm #{f}" if test ?f, f
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
61
105
|
end
|
|
62
106
|
end
|
|
63
107
|
|
|
64
108
|
desc "generate a bunch of stuff with generators"
|
|
65
109
|
task :stuff do
|
|
66
|
-
in_example_app "bundle install"
|
|
67
110
|
in_example_app "rake rails:template LOCATION='../../templates/generate_stuff.rb'"
|
|
68
111
|
end
|
|
69
112
|
end
|
|
@@ -114,5 +157,3 @@ task :relish, :version do |t, args|
|
|
|
114
157
|
end
|
|
115
158
|
|
|
116
159
|
task :default => [:spec, "clobber:app", "generate:app", "generate:stuff", :smoke, :cucumber]
|
|
117
|
-
|
|
118
|
-
|
data/Thorfile
CHANGED
|
@@ -1,25 +1,40 @@
|
|
|
1
|
-
class
|
|
2
|
-
desc "
|
|
3
|
-
def
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
class Gemfile < Thor
|
|
2
|
+
desc "use VERSION", "installs the bundle using gemfiles/rails-VERSION"
|
|
3
|
+
def use(version)
|
|
4
|
+
"gemfiles/rails-#{version}".tap do |gemfile|
|
|
5
|
+
ENV["BUNDLE_GEMFILE"] = File.expand_path(gemfile)
|
|
6
|
+
say "Using #{gemfile}"
|
|
7
|
+
end
|
|
8
|
+
"bundle install --binstubs".tap do |m|
|
|
9
|
+
say m
|
|
10
|
+
system m
|
|
9
11
|
end
|
|
12
|
+
unless version =~ /^\d\.\d\.\d/
|
|
13
|
+
"bundle update rails".tap do |m|
|
|
14
|
+
say m
|
|
15
|
+
system m
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
say `ln -s gemfiles/bin` unless File.exist?('bin')
|
|
19
|
+
`echo rails-#{version} > ./.gemfile`
|
|
10
20
|
end
|
|
11
21
|
|
|
12
|
-
desc "
|
|
13
|
-
def
|
|
14
|
-
|
|
15
|
-
`git fetch`
|
|
16
|
-
end
|
|
22
|
+
desc "which", "print out the configured gemfile"
|
|
23
|
+
def which
|
|
24
|
+
say `cat ./.gemfile`
|
|
17
25
|
end
|
|
18
26
|
|
|
19
|
-
desc "
|
|
20
|
-
def
|
|
21
|
-
`
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
desc "list", "list the available options for 'thor gemfile:use'"
|
|
28
|
+
def list
|
|
29
|
+
all = `ls gemfiles`.chomp.split.grep(/^rails/).reject {|i| i =~ /lock$/}
|
|
30
|
+
|
|
31
|
+
versions = all.grep(/^rails-\d\.\d/)
|
|
32
|
+
branches = all - versions
|
|
33
|
+
|
|
34
|
+
puts "releases:"
|
|
35
|
+
versions.sort.reverse.each {|i| puts i}
|
|
36
|
+
puts
|
|
37
|
+
puts "branches:"
|
|
38
|
+
branches.sort.reverse.each {|i| puts i}
|
|
24
39
|
end
|
|
25
40
|
end
|
data/features/.nav
CHANGED
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,27 @@
|
|
|
1
|
+
### 2.6.0 / 2011-05-12
|
|
2
|
+
|
|
3
|
+
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.5.0...v2.6.0)
|
|
4
|
+
|
|
5
|
+
* Enhancements
|
|
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
|
+
* Update the controller spec generated by the rails scaffold generator:
|
|
11
|
+
* Add documentation to the generated spec
|
|
12
|
+
* Use `any_instance` to avoid stubbing finders
|
|
13
|
+
* Use real objects instead of `mock_model`
|
|
14
|
+
* Update capybara integration to work with capy 0.4 and 1.0.0.beta
|
|
15
|
+
* Decorate paths passed to `[append|prepend]_view_paths` with empty templates
|
|
16
|
+
unless rendering views. (Mark Turner)
|
|
17
|
+
|
|
18
|
+
* Bug fixes
|
|
19
|
+
* fix typo in "rake spec:statsetup" (Curtis Schofield)
|
|
20
|
+
* expose named routes in anonymous controller specs (Andy Lindeman)
|
|
21
|
+
* error when generating namespaced scaffold resources (Andy Lindeman)
|
|
22
|
+
* Fix load order issue w/ Capybara (oleg dashevskii)
|
|
23
|
+
* Fix monkey patches that broke due to internal changes in rails-3.1.0.beta1
|
|
24
|
+
|
|
1
25
|
### 2.5.0 / 2011-02-05
|
|
2
26
|
|
|
3
27
|
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.4.1...v2.5.0)
|
|
@@ -5,11 +29,11 @@
|
|
|
5
29
|
* Enhancements
|
|
6
30
|
* use index_helper instead of table_name when generating specs (Reza
|
|
7
31
|
Primardiansyah)
|
|
8
|
-
|
|
32
|
+
|
|
9
33
|
* Bug fixes
|
|
10
34
|
* fixed bug in which `render_views` in a nested group set the value in its
|
|
11
35
|
parent group.
|
|
12
|
-
* only include MailerExampleGroup when it is
|
|
36
|
+
* only include MailerExampleGroup when it is defined (Steve Sloan)
|
|
13
37
|
* mock_model.as_null_object.attribute.blank? returns false (Randy Schmidt)
|
|
14
38
|
* fix typo in request specs (Paco Guzman)
|
|
15
39
|
|
data/features/Generators.md
CHANGED
|
@@ -5,4 +5,4 @@ controllers, etc, RSpec specs are generated instead of Test::Unit tests.
|
|
|
5
5
|
|
|
6
6
|
Note that the generators are there to help you get started, but they are no
|
|
7
7
|
substitute for writing your own examples, and they are only guaranteed to work
|
|
8
|
-
out of the box for
|
|
8
|
+
out of the box for with Rails' defaults (ActiveRecord, no Capybara or Webrat).
|
data/features/GettingStarted.md
CHANGED
|
@@ -15,6 +15,10 @@ Install Rails-3
|
|
|
15
15
|
|
|
16
16
|
$ bundle install
|
|
17
17
|
|
|
18
|
+
### Bootstrap RSpec
|
|
19
|
+
|
|
20
|
+
$ rails generate rspec:install
|
|
21
|
+
|
|
18
22
|
### Generate a scaffold
|
|
19
23
|
|
|
20
24
|
$ rails generate scaffold Widgets name:string
|
|
@@ -33,8 +37,48 @@ the files in the `spec` directory to RSpec.
|
|
|
33
37
|
|
|
34
38
|
or
|
|
35
39
|
|
|
36
|
-
$ rspec spec
|
|
40
|
+
$ rspec spec --format documentation
|
|
37
41
|
|
|
38
42
|
If all went well, you should see output ending with:
|
|
39
43
|
|
|
40
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.
|
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
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Feature: controller spec
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
Scenario: simple passing example
|
|
5
4
|
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
|
6
5
|
"""
|
|
@@ -15,5 +14,5 @@ Feature: controller spec
|
|
|
15
14
|
end
|
|
16
15
|
end
|
|
17
16
|
"""
|
|
18
|
-
When I run
|
|
17
|
+
When I run `rspec spec`
|
|
19
18
|
Then the example should pass
|
|
@@ -5,7 +5,7 @@ Feature: views are stubbed by default
|
|
|
5
5
|
template an action should try to render regardless of whether the template
|
|
6
6
|
compiles cleanly.
|
|
7
7
|
|
|
8
|
-
NOTE: unlike rspec-rails-1.x, the real template must exist.
|
|
8
|
+
NOTE: unlike rspec-rails-1.x, the real template must exist.
|
|
9
9
|
|
|
10
10
|
Scenario: expect template that is rendered by controller action (passes)
|
|
11
11
|
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
|
@@ -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,52 @@ 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
|
|
|
50
|
+
Scenario: expect empty templates to render when view path is changed at runtime (passes)
|
|
51
|
+
Given a file named "spec/controllers/things_controller_spec.rb" with:
|
|
52
|
+
"""
|
|
53
|
+
require "spec_helper"
|
|
54
|
+
|
|
55
|
+
describe ThingsController do
|
|
56
|
+
describe "custom_action" do
|
|
57
|
+
it "renders an empty custom_action template" do
|
|
58
|
+
controller.prepend_view_path 'app/views'
|
|
59
|
+
controller.append_view_path 'app/views'
|
|
60
|
+
get :custom_action
|
|
61
|
+
response.should render_template("custom_action")
|
|
62
|
+
response.body.should == ""
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
"""
|
|
67
|
+
When I run `rspec spec`
|
|
68
|
+
Then the examples should all pass
|
|
69
|
+
|
|
70
|
+
Scenario: expect template to render when view path is changed at runtime (fails)
|
|
71
|
+
Given a file named "spec/controllers/things_controller_spec.rb" with:
|
|
72
|
+
"""
|
|
73
|
+
require "spec_helper"
|
|
74
|
+
|
|
75
|
+
describe ThingsController do
|
|
76
|
+
describe "custom_action" do
|
|
77
|
+
it "renders the custom_action template" do
|
|
78
|
+
render_views
|
|
79
|
+
controller.prepend_view_path 'app/views'
|
|
80
|
+
get :custom_action
|
|
81
|
+
response.should render_template("custom_action")
|
|
82
|
+
response.body.should == ""
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "renders an empty custom_action template" do
|
|
86
|
+
controller.prepend_view_path 'app/views'
|
|
87
|
+
get :custom_action
|
|
88
|
+
response.should render_template("custom_action")
|
|
89
|
+
response.body.should == ""
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
"""
|
|
94
|
+
When I run `rspec spec`
|
|
95
|
+
Then the output should contain "2 examples, 1 failure"
|
|
@@ -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
|
|