rspec-rails 2.6.0.rc2 → 2.6.0.rc4
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 +0 -1
- data/.rspec +1 -0
- data/.travis.yml +3 -5
- data/README.md +2 -0
- data/Rakefile +16 -27
- data/features/.nav +2 -0
- data/features/Changelog.md +14 -1
- data/features/GettingStarted.md +45 -1
- data/features/controller_specs/controller_spec.feature +0 -1
- data/features/controller_specs/isolation_from_views.feature +47 -1
- data/features/request_specs/request_spec.feature +49 -0
- data/features/support/env.rb +0 -1
- data/features/view_specs/view_spec.feature +10 -10
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/base.rb +29 -16
- data/gemfiles/rails-3.0.7 +5 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +74 -42
- data/lib/rspec/rails/browser_simulators.rb +5 -0
- data/lib/rspec/rails/example/controller_example_group.rb +6 -1
- data/lib/rspec/rails/example/helper_example_group.rb +4 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +5 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -1
- data/lib/rspec/rails/example/view_example_group.rb +4 -0
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +24 -8
- data/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +9 -0
- data/templates/generate_stuff.rb +7 -0
- metadata +27 -21
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,42 +1,29 @@
|
|
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
|
-
|
18
|
-
MESSAGE
|
19
|
-
exit 1
|
20
|
-
end
|
21
|
-
|
22
1
|
require 'pathname'
|
23
2
|
ENV["BUNDLE_GEMFILE"] ||= begin
|
24
3
|
version = if File.exist?("./.gemfile")
|
25
4
|
File.read("./.gemfile").chomp
|
26
5
|
else
|
27
|
-
"rails-3.0.
|
6
|
+
"rails-3.0.7"
|
28
7
|
end
|
29
8
|
File.expand_path("../gemfiles/#{version}", __FILE__)
|
30
9
|
end
|
31
10
|
puts "Using gemfile: #{ENV["BUNDLE_GEMFILE"].gsub(Pathname.new(__FILE__).dirname.to_s,'').sub(/^\//,'')}"
|
32
11
|
require "bundler"
|
33
|
-
|
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 rails:use 3.0.7'"
|
20
|
+
end
|
21
|
+
end
|
34
22
|
Bundler::GemHelper.install_tasks
|
35
23
|
|
36
24
|
require 'rake'
|
37
25
|
require 'yaml'
|
38
26
|
|
39
|
-
require 'rake/rdoctask'
|
40
27
|
require 'rspec'
|
41
28
|
require 'rspec/core/rake_task'
|
42
29
|
|
@@ -83,10 +70,12 @@ namespace :generate do
|
|
83
70
|
desc "generate a fresh app with rspec installed"
|
84
71
|
task :app do |t|
|
85
72
|
unless File.directory?('./tmp/example_app')
|
86
|
-
sh "
|
73
|
+
sh "rails new ./tmp/example_app"
|
87
74
|
bindir = File.expand_path("gemfiles/bin")
|
88
|
-
|
89
|
-
|
75
|
+
if test ?d, bindir
|
76
|
+
Dir.chdir("./tmp/example_app") do
|
77
|
+
sh "ln -s #{bindir}"
|
78
|
+
end
|
90
79
|
end
|
91
80
|
end
|
92
81
|
end
|
data/features/.nav
CHANGED
data/features/Changelog.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
+
### 2.6.0.rc4 / 2011-05-01
|
2
|
+
|
3
|
+
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.6.0.rc2...v2.6.0.rc4)
|
4
|
+
|
5
|
+
* Enhancements
|
6
|
+
* Update the controller spec generated by the rails scaffold generator:
|
7
|
+
* Add documentation to the generated spec
|
8
|
+
* Use `any_instance` to avoid stubbing finders
|
9
|
+
* Use real objects instead of `mock_model`
|
10
|
+
* Update capybara integration to work with capy 0.4 and 1.0.0.beta
|
11
|
+
* Decorate paths passed to `[append|prepend]_view_paths` with empty templates
|
12
|
+
unless rendering views. (Mark Turner)
|
13
|
+
|
1
14
|
### 2.6.0.rc2 / 2011-04-18
|
2
15
|
|
3
|
-
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.5.0...v2.6.
|
16
|
+
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.5.0...v2.6.0.rc2)
|
4
17
|
|
5
18
|
* Enhancments
|
6
19
|
* rails 3 shortcuts for routing specs (Joe Fiorini)
|
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.
|
@@ -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:
|
@@ -47,3 +47,49 @@ Feature: views are stubbed by default
|
|
47
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"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Feature: request spec
|
2
|
+
|
3
|
+
Request specs provide a thin wrapper around Rails' integration tests, and are
|
4
|
+
designed to drive behavior through the full stack, including routing
|
5
|
+
(provided by Rails) and without stubbing (that's up to you).
|
6
|
+
|
7
|
+
With request specs, you can:
|
8
|
+
|
9
|
+
* specify a single request
|
10
|
+
* specify multiple requests across multiple controllers
|
11
|
+
* specify multiple requests across multiple sessions
|
12
|
+
|
13
|
+
Check the rails documentation on integration tests for more information.
|
14
|
+
|
15
|
+
RSpec provides two matchers that delegate to Rails assertions:
|
16
|
+
|
17
|
+
render_template # delegates to assert_template
|
18
|
+
redirect_to # delegates to assert_redirected_to
|
19
|
+
|
20
|
+
Check the Rails docs for details on these methods as well.
|
21
|
+
|
22
|
+
If you would like to use webrat or capybara with your request specs, all you
|
23
|
+
have to do is include one of them in your Gemfile and RSpec will
|
24
|
+
automatically load them in a request spec.
|
25
|
+
|
26
|
+
Scenario: specify managing a Widget with Rails integration methods
|
27
|
+
Given a file named "spec/requests/widget_management_spec.rb" with:
|
28
|
+
"""
|
29
|
+
require "spec_helper"
|
30
|
+
|
31
|
+
describe "Widget management" do
|
32
|
+
|
33
|
+
it "creates a Widget and redirects to the Widget's page" do
|
34
|
+
get "/widgets/new"
|
35
|
+
response.should render_template(:new)
|
36
|
+
|
37
|
+
post "/widgets", :widget => {:name => "My Widget"}
|
38
|
+
|
39
|
+
response.should redirect_to(assigns(:widget))
|
40
|
+
follow_redirect!
|
41
|
+
|
42
|
+
response.should render_template(:show)
|
43
|
+
response.body.should include("Widget was successfully created.")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
"""
|
48
|
+
When I run `rspec spec/requests/widget_management_spec.rb`
|
49
|
+
Then the example should pass
|
data/features/support/env.rb
CHANGED
@@ -16,8 +16,8 @@ Feature: view spec
|
|
16
16
|
|
17
17
|
render
|
18
18
|
|
19
|
-
rendered.should
|
20
|
-
rendered.should
|
19
|
+
rendered.should =~ /slicer/
|
20
|
+
rendered.should =~ /dicer/
|
21
21
|
end
|
22
22
|
end
|
23
23
|
"""
|
@@ -42,8 +42,8 @@ Feature: view spec
|
|
42
42
|
it "displays both widgets" do
|
43
43
|
render
|
44
44
|
|
45
|
-
rendered.should
|
46
|
-
rendered.should
|
45
|
+
rendered.should =~ /slicer/
|
46
|
+
rendered.should =~ /dicer/
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -62,7 +62,7 @@ Feature: view spec
|
|
62
62
|
|
63
63
|
render :template => "widgets/widget.html.erb"
|
64
64
|
|
65
|
-
rendered.should
|
65
|
+
rendered.should =~ /slicer/
|
66
66
|
end
|
67
67
|
end
|
68
68
|
"""
|
@@ -84,7 +84,7 @@ Feature: view spec
|
|
84
84
|
|
85
85
|
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
|
86
86
|
|
87
|
-
rendered.should
|
87
|
+
rendered.should =~ /slicer/
|
88
88
|
end
|
89
89
|
end
|
90
90
|
"""
|
@@ -106,7 +106,7 @@ Feature: view spec
|
|
106
106
|
|
107
107
|
render "widgets/widget", :widget => widget
|
108
108
|
|
109
|
-
rendered.should
|
109
|
+
rendered.should =~ /slicer/
|
110
110
|
end
|
111
111
|
end
|
112
112
|
"""
|
@@ -127,7 +127,7 @@ Feature: view spec
|
|
127
127
|
|
128
128
|
render :text => "This is directly rendered"
|
129
129
|
|
130
|
-
rendered.should
|
130
|
+
rendered.should =~ /directly rendered/
|
131
131
|
end
|
132
132
|
end
|
133
133
|
"""
|
@@ -146,7 +146,7 @@ Feature: view spec
|
|
146
146
|
page.hide 'status-indicator'
|
147
147
|
end
|
148
148
|
|
149
|
-
rendered.should
|
149
|
+
rendered.should =~ /Element.hide\(\"status-indicator\"\);/
|
150
150
|
end
|
151
151
|
end
|
152
152
|
"""
|
@@ -177,7 +177,7 @@ Feature: view spec
|
|
177
177
|
|
178
178
|
it 'checks for admin access' do
|
179
179
|
render
|
180
|
-
rendered.should
|
180
|
+
rendered.should =~ /Secret admin area/
|
181
181
|
end
|
182
182
|
end
|
183
183
|
"""
|
data/gemfiles/base.rb
CHANGED
@@ -7,7 +7,7 @@ module GemfileBase
|
|
7
7
|
library_path = File.expand_path("../../../#{lib}", __FILE__)
|
8
8
|
if File.exist?(library_path)
|
9
9
|
gem lib, :path => library_path
|
10
|
-
elsif ENV["
|
10
|
+
elsif ENV["CI"] || ENV["USE_GIT_REPOS"]
|
11
11
|
gem lib, :git => "git://github.com/rspec/#{lib}.git"
|
12
12
|
else
|
13
13
|
gem lib
|
@@ -15,26 +15,39 @@ module GemfileBase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
gem 'sqlite3-ruby', :require => 'sqlite3'
|
18
|
-
|
19
|
-
|
20
|
-
gem "rcov", "0.9.9"
|
21
|
-
gem "relish", "0.2.0"
|
22
|
-
gem "guard-rspec", "0.1.9"
|
18
|
+
gem "cucumber", "~> 0.10.2"
|
19
|
+
gem "aruba", "~> 0.3.6"
|
23
20
|
gem "growl", "1.0.3"
|
24
21
|
gem "ZenTest", "~> 4.4.2"
|
25
|
-
gem "webrat", "0.7.2"
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
# gem "webrat", "0.7.2"
|
24
|
+
# gem "capybara", "~> 0.4"
|
25
|
+
# gem "capybara", "1.0.0.beta1"
|
26
|
+
|
27
|
+
unless ENV['CI']
|
28
|
+
gem "rcov", "0.9.9"
|
29
|
+
gem "relish", "0.2.0"
|
30
|
+
gem "guard-rspec", "0.1.9"
|
31
|
+
|
32
|
+
if RUBY_PLATFORM =~ /darwin/
|
33
|
+
gem "autotest-fsevent", "~> 0.2.4"
|
34
|
+
gem "autotest-growl", "~> 0.2.9"
|
35
|
+
end
|
31
36
|
|
32
|
-
|
33
|
-
|
37
|
+
platforms :mri_18 do
|
38
|
+
gem 'ruby-debug'
|
39
|
+
end
|
40
|
+
|
41
|
+
platforms :mri_19 do
|
42
|
+
gem 'linecache19', '0.5.11' # 0.5.12 cannot install on 1.9.1, and 0.5.11 appears to work with both 1.9.1 & 1.9.2
|
43
|
+
gem 'ruby-debug19'
|
44
|
+
gem 'ruby-debug-base19', RUBY_VERSION == '1.9.1' ? '0.11.23' : '~> 0.11.24'
|
45
|
+
end
|
34
46
|
|
35
|
-
|
36
|
-
|
37
|
-
|
47
|
+
platforms :ruby_18, :ruby_19 do
|
48
|
+
gem "rb-fsevent", "~> 0.3.9"
|
49
|
+
gem "ruby-prof", "~> 0.9.2"
|
50
|
+
end
|
38
51
|
end
|
39
52
|
|
40
53
|
platforms :jruby do
|
@@ -2,72 +2,95 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
4
|
# It demonstrates how one might use RSpec to specify the controller code that
|
5
|
-
# was generated by
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
#
|
15
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
16
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
17
|
+
# is no simpler way to get a handle on the object needed for the example.
|
18
|
+
# Message expectations are only used when there is no simpler way to specify
|
19
|
+
# that an instance is receiving a specific message.
|
6
20
|
|
7
21
|
describe <%= controller_class_name %>Controller do
|
8
22
|
|
9
|
-
|
10
|
-
|
23
|
+
# This should return the minimal set of attributes required to create a valid
|
24
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
25
|
+
# update the return value of this method accordingly.
|
26
|
+
def valid_attributes
|
27
|
+
{}
|
11
28
|
end
|
12
29
|
|
13
30
|
<% unless options[:singleton] -%>
|
14
31
|
describe "GET index" do
|
15
32
|
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
16
|
-
<%=
|
33
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
17
34
|
get :index
|
18
|
-
assigns(:<%= table_name %>).should eq([<%=
|
35
|
+
assigns(:<%= table_name %>).should eq([<%= file_name %>])
|
19
36
|
end
|
20
37
|
end
|
21
38
|
|
22
39
|
<% end -%>
|
23
40
|
describe "GET show" do
|
24
41
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
25
|
-
<%=
|
26
|
-
get :show, :id =>
|
27
|
-
assigns(:<%= ns_file_name %>).should
|
42
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
43
|
+
get :show, :id => <%= file_name %>.id.to_s
|
44
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
28
45
|
end
|
29
46
|
end
|
30
47
|
|
31
48
|
describe "GET new" do
|
32
49
|
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
|
33
|
-
<%= stub orm_class.build(class_name) %> { <%= mock_file_name %> }
|
34
50
|
get :new
|
35
|
-
assigns(:<%= ns_file_name %>).should
|
51
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
39
55
|
describe "GET edit" do
|
40
56
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
41
|
-
<%=
|
42
|
-
get :edit, :id =>
|
43
|
-
assigns(:<%= ns_file_name %>).should
|
57
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
58
|
+
get :edit, :id => <%= file_name %>.id.to_s
|
59
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
44
60
|
end
|
45
61
|
end
|
46
62
|
|
47
63
|
describe "POST create" do
|
48
64
|
describe "with valid params" do
|
65
|
+
it "creates a new <%= class_name %>" do
|
66
|
+
expect {
|
67
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
68
|
+
}.to change(<%= class_name %>, :count).by(1)
|
69
|
+
end
|
70
|
+
|
49
71
|
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
50
|
-
|
51
|
-
|
52
|
-
assigns(:<%= ns_file_name %>).should
|
72
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
73
|
+
assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
|
74
|
+
assigns(:<%= ns_file_name %>).should be_persisted
|
53
75
|
end
|
54
76
|
|
55
77
|
it "redirects to the created <%= ns_file_name %>" do
|
56
|
-
|
57
|
-
|
58
|
-
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
|
78
|
+
post :create, :<%= ns_file_name %> => valid_attributes
|
79
|
+
response.should redirect_to(<%= class_name %>.last)
|
59
80
|
end
|
60
81
|
end
|
61
82
|
|
62
83
|
describe "with invalid params" do
|
63
84
|
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
64
|
-
|
65
|
-
|
66
|
-
|
85
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
86
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
87
|
+
post :create, :<%= ns_file_name %> => {}
|
88
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
67
89
|
end
|
68
90
|
|
69
91
|
it "re-renders the 'new' template" do
|
70
|
-
|
92
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
93
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
71
94
|
post :create, :<%= ns_file_name %> => {}
|
72
95
|
response.should render_template("new")
|
73
96
|
end
|
@@ -77,34 +100,42 @@ describe <%= controller_class_name %>Controller do
|
|
77
100
|
describe "PUT update" do
|
78
101
|
describe "with valid params" do
|
79
102
|
it "updates the requested <%= ns_file_name %>" do
|
80
|
-
<%=
|
81
|
-
|
82
|
-
|
103
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
104
|
+
# Assuming there are no other <%= table_name %> in the database, this
|
105
|
+
# specifies that the <%= class_name %> created on the previous line
|
106
|
+
# receives the :update_attributes message with whatever params are
|
107
|
+
# submitted in the request.
|
108
|
+
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
|
109
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %>
|
83
110
|
end
|
84
111
|
|
85
112
|
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
86
|
-
<%=
|
87
|
-
put :update, :id =>
|
88
|
-
assigns(:<%= ns_file_name %>).should
|
113
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
114
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
|
115
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
89
116
|
end
|
90
117
|
|
91
118
|
it "redirects to the <%= ns_file_name %>" do
|
92
|
-
<%=
|
93
|
-
put :update, :id =>
|
94
|
-
response.should redirect_to(<%=
|
119
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
120
|
+
put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
|
121
|
+
response.should redirect_to(<%= file_name %>)
|
95
122
|
end
|
96
123
|
end
|
97
124
|
|
98
125
|
describe "with invalid params" do
|
99
126
|
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
100
|
-
<%=
|
101
|
-
|
102
|
-
|
127
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
128
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
129
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
130
|
+
put :update, :id => <%= file_name %>.id.to_s
|
131
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
103
132
|
end
|
104
133
|
|
105
134
|
it "re-renders the 'edit' template" do
|
106
|
-
<%=
|
107
|
-
|
135
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
137
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
138
|
+
put :update, :id => <%= file_name %>.id.to_s
|
108
139
|
response.should render_template("edit")
|
109
140
|
end
|
110
141
|
end
|
@@ -112,14 +143,15 @@ describe <%= controller_class_name %>Controller do
|
|
112
143
|
|
113
144
|
describe "DELETE destroy" do
|
114
145
|
it "destroys the requested <%= ns_file_name %>" do
|
115
|
-
<%=
|
116
|
-
|
117
|
-
|
146
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
147
|
+
expect {
|
148
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
149
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
118
150
|
end
|
119
151
|
|
120
152
|
it "redirects to the <%= table_name %> list" do
|
121
|
-
<%=
|
122
|
-
delete :destroy, :id =>
|
153
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
154
|
+
delete :destroy, :id => <%= file_name %>.id.to_s
|
123
155
|
response.should redirect_to(<%= index_helper %>_url)
|
124
156
|
end
|
125
157
|
end
|
@@ -29,6 +29,10 @@ module RSpec::Rails
|
|
29
29
|
include Webrat::Matchers
|
30
30
|
end
|
31
31
|
|
32
|
+
capybara do
|
33
|
+
include Capybara::RSpecMatchers if defined?(Capybara::RSpecMatchers)
|
34
|
+
end
|
35
|
+
|
32
36
|
module ClassMethods
|
33
37
|
def _default_helper
|
34
38
|
base = metadata[:example_group][:description].split('/').first
|
data/lib/rspec/rails/version.rb
CHANGED
@@ -49,15 +49,15 @@ module RSpec
|
|
49
49
|
|
50
50
|
# Delegates find_all to the submitted path set and then returns templates
|
51
51
|
# with modified source
|
52
|
-
class
|
53
|
-
attr_reader :
|
52
|
+
class EmptyTemplatePathSetDecorator < ::ActionView::Resolver
|
53
|
+
attr_reader :original_path_set
|
54
54
|
|
55
|
-
def initialize(
|
56
|
-
@
|
55
|
+
def initialize(original_path_set)
|
56
|
+
@original_path_set = original_path_set
|
57
57
|
end
|
58
58
|
|
59
59
|
def find_all(*args)
|
60
|
-
|
60
|
+
original_path_set.find_all(*args).collect do |template|
|
61
61
|
::ActionView::Template.new(
|
62
62
|
"",
|
63
63
|
template.identifier,
|
@@ -71,17 +71,33 @@ module RSpec
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
module EmptyTemplates
|
75
|
+
def prepend_view_path(new_path)
|
76
|
+
lookup_context.view_paths.unshift(*_path_decorator(new_path))
|
77
|
+
end
|
78
|
+
|
79
|
+
def append_view_path(new_path)
|
80
|
+
lookup_context.view_paths.push(*_path_decorator(new_path))
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
def _path_decorator(path)
|
85
|
+
EmptyTemplatePathSetDecorator.new(::ActionView::Base::process_view_paths(path))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
74
89
|
included do
|
75
90
|
before do
|
76
91
|
unless render_views?
|
77
|
-
@
|
78
|
-
controller.class.view_paths = ::ActionView::PathSet.new.push(@
|
92
|
+
@_empty_view_path_set_delegator = EmptyTemplatePathSetDecorator.new(controller.class.view_paths)
|
93
|
+
controller.class.view_paths = ::ActionView::PathSet.new.push(@_empty_view_path_set_delegator)
|
94
|
+
controller.extend(EmptyTemplates)
|
79
95
|
end
|
80
96
|
end
|
81
97
|
|
82
98
|
after do
|
83
99
|
unless render_views?
|
84
|
-
controller.class.view_paths = @
|
100
|
+
controller.class.view_paths = @_empty_view_path_set_delegator.original_path_set
|
85
101
|
end
|
86
102
|
end
|
87
103
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,35 +9,13 @@ require 'rspec/rails'
|
|
9
9
|
|
10
10
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
11
|
|
12
|
-
# TODO - most of this is borrowed from rspec-core's spec_helper - should
|
13
|
-
# be extracted to something we can use here
|
14
|
-
def in_editor?
|
15
|
-
ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
|
16
|
-
end
|
17
|
-
|
18
12
|
class RSpec::Core::ExampleGroup
|
19
13
|
def self.run_all(reporter=nil)
|
20
14
|
run(reporter || RSpec::Mocks::Mock.new('reporter').as_null_object)
|
21
15
|
end
|
22
16
|
end
|
23
17
|
|
24
|
-
module MatchesForRSpecRailsSpecs
|
25
|
-
extend RSpec::Matchers::DSL
|
26
|
-
|
27
|
-
matcher :be_included_in_files_in do |path|
|
28
|
-
match do |mod|
|
29
|
-
stub_metadata(
|
30
|
-
:example_group => {:file_path => "#{path}whatever_spec.rb:15"}
|
31
|
-
)
|
32
|
-
group = RSpec::Core::ExampleGroup.describe
|
33
|
-
group.included_modules.include?(mod)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
18
|
RSpec.configure do |c|
|
39
|
-
c.include MatchesForRSpecRailsSpecs
|
40
|
-
c.color_enabled = !in_editor?
|
41
19
|
c.before(:each) do
|
42
20
|
@real_world = RSpec.world
|
43
21
|
RSpec.instance_variable_set(:@world, RSpec::Core::World.new)
|
data/templates/generate_stuff.rb
CHANGED
@@ -10,5 +10,12 @@ generate('observer widget')
|
|
10
10
|
generate('scaffold gadget') # scaffold with no attributes
|
11
11
|
generate('scaffold admin/accounts name:string') # scaffold with nested resource
|
12
12
|
|
13
|
+
generate('controller things custom_action')
|
14
|
+
template_code= <<-TEMPLATE
|
15
|
+
<% raise 'Error from custom_action because we should never render this template....derp derp derp' %>
|
16
|
+
TEMPLATE
|
17
|
+
|
18
|
+
file "app/views/things/custom_action.html.erb", template_code, {:force=>true}
|
19
|
+
|
13
20
|
run('rake db:migrate')
|
14
21
|
run('rake db:test:prepare')
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424061
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 6
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 2.6.0.
|
11
|
+
- 4
|
12
|
+
version: 2.6.0.rc4
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- David Chelimsky
|
@@ -17,13 +17,10 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-05-01 00:00:00 -04:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
|
-
prerelease: false
|
25
|
-
type: :runtime
|
26
|
-
name: activesupport
|
27
24
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
@@ -34,11 +31,11 @@ dependencies:
|
|
34
31
|
- 3
|
35
32
|
- 0
|
36
33
|
version: "3.0"
|
37
|
-
requirement: *id001
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
34
|
prerelease: false
|
40
35
|
type: :runtime
|
41
|
-
|
36
|
+
requirement: *id001
|
37
|
+
name: activesupport
|
38
|
+
- !ruby/object:Gem::Dependency
|
42
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
43
40
|
none: false
|
44
41
|
requirements:
|
@@ -49,11 +46,11 @@ dependencies:
|
|
49
46
|
- 3
|
50
47
|
- 0
|
51
48
|
version: "3.0"
|
52
|
-
requirement: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
49
|
prerelease: false
|
55
50
|
type: :runtime
|
56
|
-
|
51
|
+
requirement: *id002
|
52
|
+
name: actionpack
|
53
|
+
- !ruby/object:Gem::Dependency
|
57
54
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
55
|
none: false
|
59
56
|
requirements:
|
@@ -64,25 +61,28 @@ dependencies:
|
|
64
61
|
- 3
|
65
62
|
- 0
|
66
63
|
version: "3.0"
|
67
|
-
requirement: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
64
|
prerelease: false
|
70
65
|
type: :runtime
|
71
|
-
|
66
|
+
requirement: *id003
|
67
|
+
name: railties
|
68
|
+
- !ruby/object:Gem::Dependency
|
72
69
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
70
|
none: false
|
74
71
|
requirements:
|
75
72
|
- - "="
|
76
73
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
74
|
+
hash: 15424061
|
78
75
|
segments:
|
79
76
|
- 2
|
80
77
|
- 6
|
81
78
|
- 0
|
82
79
|
- rc
|
83
|
-
-
|
84
|
-
version: 2.6.0.
|
80
|
+
- 4
|
81
|
+
version: 2.6.0.rc4
|
82
|
+
prerelease: false
|
83
|
+
type: :runtime
|
85
84
|
requirement: *id004
|
85
|
+
name: rspec
|
86
86
|
description: RSpec-2 for Rails-3
|
87
87
|
email: dchelimsky@gmail.com
|
88
88
|
executables: []
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- features/model_specs/README.md
|
128
128
|
- features/model_specs/errors_on.feature
|
129
129
|
- features/model_specs/transactional_examples.feature
|
130
|
+
- features/request_specs/request_spec.feature
|
130
131
|
- features/routing_specs/README.md
|
131
132
|
- features/routing_specs/be_routable_matcher.feature
|
132
133
|
- features/routing_specs/named_routes.feature
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- features/view_specs/inferred_controller_path.feature
|
138
139
|
- features/view_specs/stub_template.feature
|
139
140
|
- features/view_specs/view_spec.feature
|
141
|
+
- gemfiles/.bundle/config
|
140
142
|
- gemfiles/base.rb
|
141
143
|
- gemfiles/rails-3-0-stable
|
142
144
|
- gemfiles/rails-3.0.0
|
@@ -146,6 +148,7 @@ files:
|
|
146
148
|
- gemfiles/rails-3.0.4
|
147
149
|
- gemfiles/rails-3.0.5
|
148
150
|
- gemfiles/rails-3.0.6
|
151
|
+
- gemfiles/rails-3.0.7
|
149
152
|
- gemfiles/rails-master
|
150
153
|
- lib/autotest/rails_rspec2.rb
|
151
154
|
- lib/generators/rspec.rb
|
@@ -233,6 +236,7 @@ files:
|
|
233
236
|
- spec/rspec/rails/view_rendering_spec.rb
|
234
237
|
- spec/spec_helper.rb
|
235
238
|
- spec/support/helpers.rb
|
239
|
+
- spec/support/matchers.rb
|
236
240
|
- templates/generate_stuff.rb
|
237
241
|
- templates/run_specs.rb
|
238
242
|
has_rdoc: true
|
@@ -267,10 +271,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
271
|
requirements: []
|
268
272
|
|
269
273
|
rubyforge_project: rspec
|
270
|
-
rubygems_version: 1.
|
274
|
+
rubygems_version: 1.6.2
|
271
275
|
signing_key:
|
272
276
|
specification_version: 3
|
273
|
-
summary: rspec-rails-2.6.0.
|
277
|
+
summary: rspec-rails-2.6.0.rc4
|
274
278
|
test_files:
|
275
279
|
- features/Autotest.md
|
276
280
|
- features/Changelog.md
|
@@ -294,6 +298,7 @@ test_files:
|
|
294
298
|
- features/model_specs/README.md
|
295
299
|
- features/model_specs/errors_on.feature
|
296
300
|
- features/model_specs/transactional_examples.feature
|
301
|
+
- features/request_specs/request_spec.feature
|
297
302
|
- features/routing_specs/README.md
|
298
303
|
- features/routing_specs/be_routable_matcher.feature
|
299
304
|
- features/routing_specs/named_routes.feature
|
@@ -331,3 +336,4 @@ test_files:
|
|
331
336
|
- spec/rspec/rails/view_rendering_spec.rb
|
332
337
|
- spec/spec_helper.rb
|
333
338
|
- spec/support/helpers.rb
|
339
|
+
- spec/support/matchers.rb
|