rspec-rails 2.0.0.beta.8 → 2.0.0.beta.9.1
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/README.markdown +82 -27
- data/Rakefile +7 -7
- data/Upgrade.markdown +12 -0
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -0
- data/cucumber.yml +3 -0
- data/example_app_template.rb +2 -2
- data/features/controller_specs/do_not_render_views.feature +61 -0
- data/features/controller_specs/readers.feature +18 -0
- data/features/controller_specs/render_views.feature +53 -0
- data/features/model_specs/errors_on.feature +32 -0
- data/features/model_specs/transactional_examples.feature +2 -2
- data/features/view_specs/view_spec.feature +102 -1
- data/lib/autotest/rails_rspec2.rb +1 -1
- data/lib/generators/rspec/helper/helper_generator.rb +1 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +3 -3
- data/lib/generators/rspec/install/install_generator.rb +7 -7
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +10 -1
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/rspec-rails.rb +12 -0
- data/lib/rspec/rails.rb +8 -0
- data/lib/rspec/rails/adapters.rb +12 -8
- data/lib/rspec/rails/example.rb +1 -0
- data/lib/rspec/rails/example/controller_example_group.rb +13 -12
- data/lib/rspec/rails/example/helper_example_group.rb +43 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +10 -5
- data/lib/rspec/rails/example/request_example_group.rb +7 -7
- data/lib/rspec/rails/example/view_example_group.rb +44 -62
- data/lib/rspec/rails/extensions.rb +1 -0
- data/lib/rspec/rails/extensions/active_record/base.rb +46 -0
- data/lib/rspec/rails/matchers.rb +28 -3
- data/lib/rspec/rails/mocks.rb +3 -3
- data/lib/rspec/rails/monkey.rb +1 -0
- data/lib/rspec/rails/monkey/action_controller/test_case.rb +153 -145
- data/lib/rspec/rails/monkey/action_view/test_case.rb +201 -0
- data/lib/rspec/rails/null_resolver.rb +10 -0
- data/lib/{generators/rspec/install/templates/lib → rspec/rails}/tasks/rspec.rake +4 -5
- data/lib/rspec/rails/transactional_database_support.rb +4 -6
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +28 -0
- data/lib/rspec/rails/view_rendering.rb +33 -0
- data/rspec-rails.gemspec +41 -11
- data/spec/rspec/rails/example/controller_example_group_spec.rb +11 -0
- data/spec/rspec/rails/example/helper_example_group_spec.rb +20 -0
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +11 -0
- data/spec/rspec/rails/example/request_example_group_spec.rb +11 -0
- data/spec/rspec/rails/example/view_example_group_spec.rb +75 -0
- data/spec/rspec/rails/example/view_rendering_spec.rb +68 -0
- data/spec/rspec/rails/matchers/errors_on_spec.rb +38 -0
- data/spec/rspec/rails/mocks/ar_classes.rb +1 -1
- data/spec/rspec/rails/mocks/mock_model_spec.rb +88 -65
- data/spec/rspec/rails/mocks/stub_model_spec.rb +1 -1
- data/spec/rspec/rails/transactional_database_support_spec.rb +2 -2
- data/spec/spec_helper.rb +18 -2
- data/spec/support/helpers.rb +20 -0
- data/specs.watchr +10 -10
- data/templates/generate_stuff.rb +3 -1
- metadata +40 -9
data/README.markdown
CHANGED
@@ -1,17 +1,11 @@
|
|
1
|
-
|
1
|
+
# rspec-rails-2
|
2
2
|
|
3
|
-
|
3
|
+
## RSpec-2 for Rails-3
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
either rspec or rails.
|
5
|
+
rspec-rails-2 brings rspec-2 to rails-3 with lightweight extensions to both
|
6
|
+
libraries.
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
Currently in alpha - some things work, some not so much - see Known Issues,
|
12
|
-
below
|
13
|
-
|
14
|
-
Install:
|
8
|
+
## Install
|
15
9
|
|
16
10
|
gem install rspec-rails --pre
|
17
11
|
|
@@ -23,7 +17,7 @@ This installs the following gems:
|
|
23
17
|
* rspec-mocks
|
24
18
|
* rspec-rails
|
25
19
|
|
26
|
-
Configure:
|
20
|
+
## Configure:
|
27
21
|
|
28
22
|
Add this line to the Gemfile:
|
29
23
|
|
@@ -39,16 +33,36 @@ the "rake spec" task.
|
|
39
33
|
Note that things are in flux, so some generators generate code that
|
40
34
|
doesn't work all that well yet.
|
41
35
|
|
42
|
-
|
36
|
+
## Living on edge
|
37
|
+
|
38
|
+
If you prefer to exploit bundler's support for pointing a gem at a github repo,
|
39
|
+
be sure to do so for all five of the relevant rspec gems:
|
40
|
+
|
41
|
+
gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"
|
42
|
+
gem "rspec", :git => "git://github.com/rspec/rspec.git"
|
43
|
+
gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
|
44
|
+
gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
|
45
|
+
gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
|
46
|
+
|
47
|
+
Keep in mind that each of these repos is under active development, which means
|
48
|
+
that its very likely that you'll pull from these repos and they won't play nice
|
49
|
+
together. If playing nice is important to you, stick to the published gems.
|
50
|
+
|
51
|
+
## Backwards compatibility
|
52
|
+
|
53
|
+
This is a complete rewrite of the rspec-rails extension designed to work with
|
54
|
+
rails-3.x and rspec-2.x. It will not work with older versions of either rspec
|
55
|
+
or rails. Many of the APIs from rspec-rails-1 have been carried forward,
|
56
|
+
however, so upgrading an app from rspec-1/rails-2, while not pain-free, should
|
57
|
+
not send you to the doctor with a migraine.
|
43
58
|
|
44
|
-
|
59
|
+
## Synopsis
|
45
60
|
|
46
61
|
* each example runs in its own transaction
|
47
|
-
* configurable in
|
48
|
-
* see generated spec/
|
62
|
+
* configurable in RSpec.configure
|
63
|
+
* see generated spec/spec\_helper.rb
|
49
64
|
* model specs in spec/models
|
50
65
|
* controller specs in spec/controllers
|
51
|
-
* no view isolation yet
|
52
66
|
* view specs in spec/views
|
53
67
|
* mailer specs in spec/mailers
|
54
68
|
* observer specs in spec/models
|
@@ -56,20 +70,23 @@ Currently supported:
|
|
56
70
|
* these wrap rails integration tests
|
57
71
|
* rails assertions
|
58
72
|
* assertion-wrapping matchers
|
59
|
-
*
|
60
|
-
*
|
61
|
-
|
73
|
+
* redirect\_to
|
74
|
+
* render\_template
|
75
|
+
* helper specs
|
62
76
|
* webrat matchers
|
63
77
|
* generators
|
64
78
|
* run "script/rails g" to see the list of available generators
|
65
79
|
|
66
|
-
|
80
|
+
## Known issues
|
67
81
|
|
68
|
-
|
69
|
-
* no routing specs
|
70
|
-
* only works with ActiveRecord
|
82
|
+
See http://github.com/rspec/rspec-rails/issues
|
71
83
|
|
72
|
-
|
84
|
+
# Request Specs
|
85
|
+
|
86
|
+
Request specs live in spec/requests, and mix in behavior
|
87
|
+
from Rails' integration tests.
|
88
|
+
|
89
|
+
# Controller Specs
|
73
90
|
|
74
91
|
Controller specs live in spec/controllers, and mix in
|
75
92
|
ActionController::TestCase::Behavior. See the documentation
|
@@ -78,12 +95,22 @@ available from Rails.
|
|
78
95
|
|
79
96
|
You can use RSpec expectations/matchers or Test::Unit assertions.
|
80
97
|
|
98
|
+
## rendering views
|
99
|
+
By default, controller specs do not render views (as of beta.9).
|
100
|
+
This supports specifying controllers without concern for whether
|
101
|
+
the views they render work correctly or even exist. If you prefer
|
102
|
+
to render the views (a la Rails' functional tests), you can use the
|
103
|
+
`render_views` declaration in each example group:
|
104
|
+
|
105
|
+
describe SomeController do
|
106
|
+
render_views
|
107
|
+
...
|
108
|
+
|
109
|
+
## Matchers
|
81
110
|
In addition to what Rails offers, controller specs provide all
|
82
111
|
of rspec-core's matchers and the rspec-rails' specific matchers
|
83
112
|
as well.
|
84
113
|
|
85
|
-
## Matchers
|
86
|
-
|
87
114
|
### render_template
|
88
115
|
Delegates to Rails' assert_template:
|
89
116
|
|
@@ -94,3 +121,31 @@ Delegates to assert_redirect
|
|
94
121
|
|
95
122
|
response.should redirect_to(widgets_path)
|
96
123
|
|
124
|
+
# View specs
|
125
|
+
|
126
|
+
View specs live in spec/views, and mix in ActionView::TestCase::Behavior.
|
127
|
+
|
128
|
+
describe "events/show.html.erb" do
|
129
|
+
it "displays the event location" do
|
130
|
+
assign(:event, stub_model(Event,
|
131
|
+
:location => "Chicago"
|
132
|
+
)
|
133
|
+
render
|
134
|
+
rendered.should contain("Chicago")
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Helper specs
|
139
|
+
|
140
|
+
Helper specs live in spec/helpers, and mix in ActionView::TestCase::Behavior.
|
141
|
+
|
142
|
+
describe EventsHelper do
|
143
|
+
describe "#link_to_event" do
|
144
|
+
it "displays the title, and formatted date" do
|
145
|
+
event = Event.new("Ruby Kaigi", Date.new(2010, 8, 27))
|
146
|
+
# helper is an instance of ActionView::Base configured with the
|
147
|
+
# EventsHelper and all of Rails' built-in helpers
|
148
|
+
helper.link_to_event.should =~ /Ruby Kaigi, 27 Aug, 2010/
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
5
5
|
|
6
6
|
require 'rake/rdoctask'
|
7
7
|
require 'rspec/rails/version'
|
@@ -9,7 +9,7 @@ require 'rspec'
|
|
9
9
|
require 'rspec/core/rake_task'
|
10
10
|
require 'cucumber/rake/task'
|
11
11
|
|
12
|
-
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
13
|
Cucumber::Rake::Task.new(:cucumber) do |t|
|
14
14
|
t.cucumber_opts = %w{--format progress}
|
15
15
|
end
|
@@ -18,14 +18,14 @@ begin
|
|
18
18
|
require 'jeweler'
|
19
19
|
Jeweler::Tasks.new do |gem|
|
20
20
|
gem.name = "rspec-rails"
|
21
|
-
gem.version =
|
22
|
-
gem.summary = "rspec-rails-#{
|
23
|
-
gem.description = "
|
21
|
+
gem.version = RSpec::Rails::Version::STRING
|
22
|
+
gem.summary = "rspec-rails-#{RSpec::Rails::Version::STRING}"
|
23
|
+
gem.description = "RSpec-2 for Rails-3"
|
24
24
|
gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
|
25
25
|
gem.homepage = "http://github.com/rspec/rspec-rails"
|
26
26
|
gem.authors = ["David Chelimsky", "Chad Humphries"]
|
27
27
|
gem.rubyforge_project = "rspec"
|
28
|
-
gem.add_dependency "rspec", gem.version
|
28
|
+
gem.add_dependency "rspec", "2.0.0.beta.9" # gem.version
|
29
29
|
gem.add_dependency "webrat", ">= 0.7.0"
|
30
30
|
gem.post_install_message = <<-EOM
|
31
31
|
#{"*"*50}
|
@@ -49,7 +49,7 @@ end
|
|
49
49
|
namespace :gem do
|
50
50
|
desc "push to gemcutter"
|
51
51
|
task :push => :build do
|
52
|
-
system "gem push pkg/rspec-rails-#{
|
52
|
+
system "gem push pkg/rspec-rails-#{RSpec::Rails::Version::STRING}.gem"
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
data/Upgrade.markdown
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Upgrade to rspec-rails-2
|
2
|
+
|
3
|
+
## What's changed
|
4
|
+
|
5
|
+
### View specs
|
6
|
+
|
7
|
+
Rails changed the way it renders partials, so to set an expectation that a partial
|
8
|
+
gets rendered:
|
9
|
+
|
10
|
+
view.should_receive(:_render_partial).
|
11
|
+
with(hash_including(:partial => "widget/row"))
|
12
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.beta.
|
1
|
+
2.0.0.beta.9.1
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/cucumber.yml
ADDED
data/example_app_template.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path('
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
2
2
|
require 'rspec/rails/version'
|
3
3
|
|
4
|
-
gem 'rspec-rails', :path => File.expand_path('
|
4
|
+
gem 'rspec-rails', :path => File.expand_path('../', __FILE__)
|
5
5
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Feature: do not render views
|
2
|
+
|
3
|
+
By default, controller specs do not render views. This
|
4
|
+
allows you specify which view template an action should
|
5
|
+
try to render regardless of whether that template exists
|
6
|
+
or compiles cleanly.
|
7
|
+
|
8
|
+
Scenario: expect template that exists and is rendered by controller (passes)
|
9
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
10
|
+
"""
|
11
|
+
require "spec_helper.rb"
|
12
|
+
|
13
|
+
describe WidgetsController do
|
14
|
+
describe "index" do
|
15
|
+
it "renders the index template" do
|
16
|
+
get :index
|
17
|
+
response.should render_template("index")
|
18
|
+
end
|
19
|
+
it "renders the widgets/index template" do
|
20
|
+
get :index
|
21
|
+
response.should render_template("widgets/index")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run "rspec ./spec"
|
27
|
+
Then I should see "2 examples, 0 failures"
|
28
|
+
|
29
|
+
Scenario: expect template that exists but is not rendered by controller (fails)
|
30
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
31
|
+
"""
|
32
|
+
require "spec_helper.rb"
|
33
|
+
|
34
|
+
describe WidgetsController do
|
35
|
+
describe "index" do
|
36
|
+
it "renders the 'new' template" do
|
37
|
+
get :index
|
38
|
+
response.should render_template("new")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
"""
|
43
|
+
When I run "rspec ./spec"
|
44
|
+
Then I should see "1 example, 1 failure"
|
45
|
+
|
46
|
+
Scenario: expect template that does not exist and is not rendered by controller (fails)
|
47
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
48
|
+
"""
|
49
|
+
require "spec_helper.rb"
|
50
|
+
|
51
|
+
describe WidgetsController do
|
52
|
+
describe "index" do
|
53
|
+
it "renders a template that does not exist" do
|
54
|
+
get :index
|
55
|
+
response.should render_template("does_not_exist")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
"""
|
60
|
+
When I run "rspec ./spec"
|
61
|
+
Then I should see "1 example, 1 failure"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: controller spec readers
|
2
|
+
|
3
|
+
Controller specs expose a number of different
|
4
|
+
attribute readers.
|
5
|
+
|
6
|
+
Scenario: access controller
|
7
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
8
|
+
"""
|
9
|
+
require "spec_helper.rb"
|
10
|
+
|
11
|
+
describe WidgetsController do
|
12
|
+
it "is available before an action" do
|
13
|
+
controller.should be_an_instance_of(WidgetsController)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
"""
|
17
|
+
When I run "rspec ./spec"
|
18
|
+
Then I should see "1 example, 0 failures"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
Feature: render views
|
2
|
+
|
3
|
+
You can tell a controller example group to render views
|
4
|
+
with the render_views declaration.
|
5
|
+
|
6
|
+
Scenario: expect template that exists and is rendered by controller (passes)
|
7
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
8
|
+
"""
|
9
|
+
require "spec_helper.rb"
|
10
|
+
|
11
|
+
describe WidgetsController do
|
12
|
+
render_views
|
13
|
+
|
14
|
+
describe "index" do
|
15
|
+
it "renders the index template" do
|
16
|
+
get :index
|
17
|
+
response.should render_template("index")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "renders the widgets/index template" do
|
21
|
+
get :index
|
22
|
+
response.should render_template("widgets/index")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
When I run "rspec ./spec"
|
28
|
+
Then I should see "2 examples, 0 failures"
|
29
|
+
|
30
|
+
Scenario: expect template that does not exist and is rendered by controller (passes)
|
31
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
32
|
+
"""
|
33
|
+
require "spec_helper.rb"
|
34
|
+
|
35
|
+
describe WidgetsController do
|
36
|
+
render_views
|
37
|
+
|
38
|
+
before do
|
39
|
+
def controller.index
|
40
|
+
render "other"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "index" do
|
45
|
+
it "renders the other template" do
|
46
|
+
get :index
|
47
|
+
response.should render_template("other")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
"""
|
52
|
+
When I run "rspec ./spec"
|
53
|
+
Then I should see "1 example, 1 failure"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature: errors_on
|
2
|
+
|
3
|
+
Scenario: with one validation error
|
4
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
5
|
+
"""
|
6
|
+
require "spec_helper"
|
7
|
+
|
8
|
+
class ValidatingWidget < ActiveRecord::Base
|
9
|
+
set_table_name :widgets
|
10
|
+
validates_presence_of :name
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ValidatingWidget do
|
14
|
+
it "fails validation with no name (using error_on)" do
|
15
|
+
ValidatingWidget.new.should have(1).error_on(:name)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "fails validation with no name (using errors_on)" do
|
19
|
+
ValidatingWidget.new.should have(1).errors_on(:name)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "passes validation with a name (using 0)" do
|
23
|
+
ValidatingWidget.new(:name => "liquid nitrogen").should have(0).errors_on(:name)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "passes validation with a name (using :no)" do
|
27
|
+
ValidatingWidget.new(:name => "liquid nitrogen").should have(:no).errors_on(:name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
"""
|
31
|
+
When I run "rspec spec/models/widget_spec.rb"
|
32
|
+
Then I should see "4 examples, 0 failures"
|
@@ -28,7 +28,7 @@ Feature: transactional examples
|
|
28
28
|
"""
|
29
29
|
require "spec_helper"
|
30
30
|
|
31
|
-
|
31
|
+
RSpec.configure do |c|
|
32
32
|
c.use_transactional_examples = true
|
33
33
|
end
|
34
34
|
|
@@ -55,7 +55,7 @@ Feature: transactional examples
|
|
55
55
|
"""
|
56
56
|
require "spec_helper"
|
57
57
|
|
58
|
-
|
58
|
+
RSpec.configure do |c|
|
59
59
|
c.use_transactional_examples = false
|
60
60
|
end
|
61
61
|
|
@@ -2,7 +2,7 @@ Feature: view spec
|
|
2
2
|
|
3
3
|
View specs live in spec/views and render view templates in isolation.
|
4
4
|
|
5
|
-
Scenario: passing spec
|
5
|
+
Scenario: passing spec that renders the described view file
|
6
6
|
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
7
7
|
"""
|
8
8
|
require "spec_helper"
|
@@ -51,3 +51,104 @@ Feature: view spec
|
|
51
51
|
When I run "rspec spec/views"
|
52
52
|
Then I should see "1 example, 0 failures"
|
53
53
|
|
54
|
+
Scenario: passing spec with explicit template rendering
|
55
|
+
Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
|
56
|
+
"""
|
57
|
+
require "spec_helper"
|
58
|
+
|
59
|
+
describe "rendering the widget template" do
|
60
|
+
it "displays the widget" do
|
61
|
+
assign(:widget, stub_model(Widget, :name => "slicer"))
|
62
|
+
|
63
|
+
render :template => "widgets/widget.html.erb"
|
64
|
+
|
65
|
+
response.should contain("slicer")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
"""
|
69
|
+
And a file named "app/views/widgets/widget.html.erb" with:
|
70
|
+
"""
|
71
|
+
<h2><%= @widget.name %></h2>
|
72
|
+
"""
|
73
|
+
When I run "rspec spec/views"
|
74
|
+
Then I should see "1 example, 0 failures"
|
75
|
+
|
76
|
+
Scenario: passing spec with rendering of locals in a partial
|
77
|
+
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
78
|
+
"""
|
79
|
+
require "spec_helper"
|
80
|
+
|
81
|
+
describe "rendering locals in a partial" do
|
82
|
+
it "displays the widget" do
|
83
|
+
widget = stub_model(Widget, :name => "slicer")
|
84
|
+
|
85
|
+
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
|
86
|
+
|
87
|
+
response.should contain("slicer")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
"""
|
91
|
+
And a file named "app/views/widgets/_widget.html.erb" with:
|
92
|
+
"""
|
93
|
+
<h3><%= widget.name %></h3>
|
94
|
+
"""
|
95
|
+
When I run "rspec spec/views"
|
96
|
+
Then I should see "1 example, 0 failures"
|
97
|
+
|
98
|
+
Scenario: passing spec with rendering of locals in an implicit partial
|
99
|
+
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
100
|
+
"""
|
101
|
+
require "spec_helper"
|
102
|
+
|
103
|
+
describe "rendering locals in a partial" do
|
104
|
+
it "displays the widget" do
|
105
|
+
widget = stub_model(Widget, :name => "slicer")
|
106
|
+
|
107
|
+
render "widgets/widget", :widget => widget
|
108
|
+
|
109
|
+
response.should contain("slicer")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
"""
|
113
|
+
And a file named "app/views/widgets/_widget.html.erb" with:
|
114
|
+
"""
|
115
|
+
<h3><%= widget.name %></h3>
|
116
|
+
"""
|
117
|
+
When I run "rspec spec/views"
|
118
|
+
Then I should see "1 example, 0 failures"
|
119
|
+
|
120
|
+
Scenario: passing spec with rendering of text
|
121
|
+
Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with:
|
122
|
+
"""
|
123
|
+
require "spec_helper"
|
124
|
+
|
125
|
+
describe "rendering text directly" do
|
126
|
+
it "displays the given text" do
|
127
|
+
|
128
|
+
render :text => "This is directly rendered"
|
129
|
+
|
130
|
+
response.should contain("directly rendered")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
"""
|
134
|
+
When I run "rspec spec/views"
|
135
|
+
Then I should see "1 example, 0 failures"
|
136
|
+
|
137
|
+
Scenario: passing spec with rendering of Prototype helper update
|
138
|
+
Given a file named "spec/views/widgets/prototype_update.html.erb_spec.rb" with:
|
139
|
+
"""
|
140
|
+
require "spec_helper"
|
141
|
+
|
142
|
+
describe "render a Prototype helper update" do
|
143
|
+
it "hides the status indicator" do
|
144
|
+
|
145
|
+
render :update do |page|
|
146
|
+
page.hide 'status-indicator'
|
147
|
+
end
|
148
|
+
|
149
|
+
response.should contain("Element.hide(\"status-indicator\")")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
"""
|
153
|
+
When I run "rspec spec/views"
|
154
|
+
Then I should see "1 example, 0 failures"
|