rspec-rails 2.0.0.beta.22 → 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 -4
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/History.md +1 -33
- data/License.txt +23 -0
- data/{README.markdown → README.md} +27 -7
- data/README_DEV.md +43 -0
- data/Rakefile +105 -35
- data/Thorfile +40 -0
- data/Upgrade.md +1 -0
- data/features/.nav +34 -0
- data/features/Autotest.md +24 -0
- data/features/Changelog.md +151 -0
- data/features/Generators.md +8 -0
- data/features/GettingStarted.md +84 -0
- data/features/README.md +58 -0
- data/features/Upgrade.md +117 -0
- data/features/controller_specs/README.md +45 -0
- data/features/controller_specs/anonymous_controller.feature +7 -7
- data/features/controller_specs/controller_spec.feature +18 -0
- data/features/controller_specs/isolation_from_views.feature +55 -8
- data/features/controller_specs/render_views.feature +63 -52
- data/features/helper_specs/helper_spec.feature +40 -6
- data/features/mailer_specs/url_helpers.feature +4 -4
- data/features/matchers/README.md +4 -0
- data/features/matchers/new_record_matcher.feature +6 -48
- data/features/matchers/redirect_to_matcher.feature +5 -6
- data/features/matchers/render_template_matcher.feature +13 -10
- data/features/mocks/mock_model.feature +29 -13
- data/features/mocks/stub_model.feature +4 -4
- data/features/model_specs/README.md +21 -0
- data/features/model_specs/errors_on.feature +2 -2
- data/features/model_specs/transactional_examples.feature +14 -9
- data/features/request_specs/request_spec.feature +49 -0
- data/features/routing_specs/README.md +17 -0
- data/features/{matchers → routing_specs}/be_routable_matcher.feature +25 -25
- data/features/routing_specs/named_routes.feature +18 -0
- data/features/routing_specs/route_to_matcher.feature +58 -0
- data/features/step_definitions/additional_cli_steps.rb +4 -0
- data/features/support/env.rb +14 -6
- data/features/view_specs/inferred_controller_path.feature +6 -6
- data/features/view_specs/stub_template.feature +51 -0
- data/features/view_specs/view_spec.feature +23 -42
- 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/autotest/rails_rspec2.rb +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +4 -4
- data/lib/generators/rspec/helper/helper_generator.rb +3 -3
- data/lib/generators/rspec/install/install_generator.rb +0 -8
- data/lib/generators/rspec/integration/integration_generator.rb +15 -1
- data/lib/generators/rspec/integration/templates/request_spec.rb +7 -1
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -2
- data/lib/generators/rspec/model/model_generator.rb +1 -1
- data/lib/generators/rspec/observer/observer_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +40 -11
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +90 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +15 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +7 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +14 -7
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +7 -2
- data/lib/generators/rspec/view/view_generator.rb +1 -1
- data/lib/rspec/rails/example/controller_example_group.rb +25 -34
- data/lib/rspec/rails/example/helper_example_group.rb +5 -11
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -14
- data/lib/rspec/rails/example/model_example_group.rb +0 -4
- data/lib/rspec/rails/example/rails_example_group.rb +0 -2
- data/lib/rspec/rails/example/request_example_group.rb +5 -30
- data/lib/rspec/rails/example/routing_example_group.rb +3 -5
- data/lib/rspec/rails/example/view_example_group.rb +20 -11
- data/lib/rspec/rails/example.rb +31 -1
- data/lib/rspec/rails/extensions/active_record/base.rb +28 -32
- data/lib/rspec/rails/fixture_support.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +5 -0
- data/lib/rspec/rails/matchers/redirect_to.rb +6 -2
- data/lib/rspec/rails/matchers/render_template.rb +5 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +24 -3
- data/lib/rspec/rails/matchers.rb +1 -1
- data/lib/rspec/rails/mocks.rb +118 -79
- data/lib/rspec/rails/module_inclusion.rb +17 -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_assigns.rb +23 -4
- data/lib/rspec/rails/view_rendering.rb +50 -13
- data/lib/rspec/rails.rb +7 -10
- data/lib/rspec-rails.rb +4 -2
- data/rspec-rails.gemspec +11 -39
- data/spec/autotest/rails_rspec2_spec.rb +25 -14
- data/spec/rspec/rails/configuration_spec.rb +26 -0
- data/spec/rspec/rails/deprecations_spec.rb +18 -0
- data/spec/rspec/rails/example/controller_example_group_spec.rb +47 -5
- data/spec/rspec/rails/example/helper_example_group_spec.rb +19 -1
- data/spec/rspec/rails/example/request_example_group_spec.rb +2 -0
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
- data/spec/rspec/rails/extensions/active_record/records_spec.rb +9 -0
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +17 -0
- data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +67 -8
- data/spec/rspec/rails/matchers/render_template_spec.rb +67 -10
- data/spec/rspec/rails/matchers/route_to_spec.rb +77 -31
- data/spec/rspec/rails/mocks/ar_classes.rb +17 -25
- data/spec/rspec/rails/mocks/mock_model_spec.rb +50 -13
- data/spec/rspec/rails/mocks/stub_model_spec.rb +121 -67
- data/spec/rspec/rails/view_rendering_spec.rb +105 -0
- data/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +9 -0
- data/templates/generate_stuff.rb +10 -2
- data/templates/run_specs.rb +2 -2
- metadata +141 -79
- data/Gemfile +0 -24
- data/Gotchas.markdown +0 -14
- data/Upgrade.markdown +0 -31
- data/autotest/discover.rb +0 -1
- data/features/README.markdown +0 -12
- data/features/controller_specs/readers.feature +0 -18
- data/features/routing_specs/access_to_named_routes.feature +0 -15
- data/lib/generators/rspec/install/templates/autotest/discover.rb +0 -2
- data/lib/rspec/rails/browser_simulators.rb +0 -30
- data/spec/rspec/rails/example/view_rendering_spec.rb +0 -110
- data/specs.watchr +0 -59
- data/templates/Gemfile +0 -18
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Feature: stub template
|
|
2
|
+
|
|
3
|
+
In order to isolate view specs from the partials rendered by the primary
|
|
4
|
+
view, rspec-rails (since 2.2) provides the stub_template method.
|
|
5
|
+
|
|
6
|
+
Scenario: stub template that does not exist
|
|
7
|
+
Given a file named "spec/views/gadgets/list.html.erb_spec.rb" with:
|
|
8
|
+
"""
|
|
9
|
+
require "spec_helper"
|
|
10
|
+
|
|
11
|
+
describe "gadgets/list.html.erb" do
|
|
12
|
+
it "renders the gadget partial for each gadget" do
|
|
13
|
+
assign(:gadgets, [
|
|
14
|
+
mock_model(Gadget, :id => 1, :name => "First"),
|
|
15
|
+
mock_model(Gadget, :id => 2, :name => "Second")
|
|
16
|
+
])
|
|
17
|
+
stub_template "gadgets/_gadget.html.erb" => "<%= gadget.name %><br/>"
|
|
18
|
+
render
|
|
19
|
+
rendered.should =~ /First/
|
|
20
|
+
rendered.should =~ /Second/
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
And a file named "app/views/gadgets/list.html.erb" with:
|
|
26
|
+
"""
|
|
27
|
+
<%= render :partial => "gadget", :collection => @gadgets %>
|
|
28
|
+
"""
|
|
29
|
+
When I run `rspec spec/views/gadgets/list.html.erb_spec.rb`
|
|
30
|
+
Then the examples should all pass
|
|
31
|
+
|
|
32
|
+
Scenario: stub template that exists
|
|
33
|
+
Given a file named "spec/views/gadgets/edit.html.erb_spec.rb" with:
|
|
34
|
+
"""
|
|
35
|
+
require "spec_helper"
|
|
36
|
+
|
|
37
|
+
describe "gadgets/edit.html.erb" do
|
|
38
|
+
before(:each) do
|
|
39
|
+
@gadget = assign(:gadget, stub_model(Gadget))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "renders the form partial" do
|
|
43
|
+
stub_template "gadgets/_form.html.erb" => "This content"
|
|
44
|
+
render
|
|
45
|
+
rendered.should =~ /This content/
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
"""
|
|
49
|
+
When I run `rspec spec/views/gadgets/edit.html.erb_spec.rb`
|
|
50
|
+
Then the examples should all pass
|
|
51
|
+
|
|
@@ -16,13 +16,13 @@ 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
|
"""
|
|
24
|
-
When I run
|
|
25
|
-
Then the
|
|
24
|
+
When I run `rspec spec/views`
|
|
25
|
+
Then the examples should all pass
|
|
26
26
|
|
|
27
27
|
Scenario: passing spec with before and nesting
|
|
28
28
|
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
|
@@ -42,14 +42,14 @@ 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
|
|
50
50
|
"""
|
|
51
|
-
When I run
|
|
52
|
-
Then the
|
|
51
|
+
When I run `rspec spec/views`
|
|
52
|
+
Then the examples should all pass
|
|
53
53
|
|
|
54
54
|
Scenario: passing spec with explicit template rendering
|
|
55
55
|
Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
|
|
@@ -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
|
"""
|
|
@@ -70,8 +70,8 @@ Feature: view spec
|
|
|
70
70
|
"""
|
|
71
71
|
<h2><%= @widget.name %></h2>
|
|
72
72
|
"""
|
|
73
|
-
When I run
|
|
74
|
-
Then the
|
|
73
|
+
When I run `rspec spec/views`
|
|
74
|
+
Then the examples should all pass
|
|
75
75
|
|
|
76
76
|
Scenario: passing spec with rendering of locals in a partial
|
|
77
77
|
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
|
@@ -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
|
"""
|
|
@@ -92,8 +92,8 @@ Feature: view spec
|
|
|
92
92
|
"""
|
|
93
93
|
<h3><%= widget.name %></h3>
|
|
94
94
|
"""
|
|
95
|
-
When I run
|
|
96
|
-
Then the
|
|
95
|
+
When I run `rspec spec/views`
|
|
96
|
+
Then the examples should all pass
|
|
97
97
|
|
|
98
98
|
Scenario: passing spec with rendering of locals in an implicit partial
|
|
99
99
|
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
|
@@ -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
|
"""
|
|
@@ -114,8 +114,8 @@ Feature: view spec
|
|
|
114
114
|
"""
|
|
115
115
|
<h3><%= widget.name %></h3>
|
|
116
116
|
"""
|
|
117
|
-
When I run
|
|
118
|
-
Then the
|
|
117
|
+
When I run `rspec spec/views`
|
|
118
|
+
Then the examples should all pass
|
|
119
119
|
|
|
120
120
|
Scenario: passing spec with rendering of text
|
|
121
121
|
Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with:
|
|
@@ -127,31 +127,12 @@ 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
|
"""
|
|
134
|
-
When I run
|
|
135
|
-
Then the
|
|
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
|
-
rendered.should contain("Element.hide(\"status-indicator\")")
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
"""
|
|
153
|
-
When I run "rspec spec/views"
|
|
154
|
-
Then the output should contain "1 example, 0 failures"
|
|
134
|
+
When I run `rspec spec/views`
|
|
135
|
+
Then the examples should all pass
|
|
155
136
|
|
|
156
137
|
Scenario: spec with view that accesses helper_method helpers
|
|
157
138
|
Given a file named "app/views/secrets/index.html.erb" with:
|
|
@@ -177,9 +158,9 @@ Feature: view spec
|
|
|
177
158
|
|
|
178
159
|
it 'checks for admin access' do
|
|
179
160
|
render
|
|
180
|
-
rendered.should
|
|
161
|
+
rendered.should =~ /Secret admin area/
|
|
181
162
|
end
|
|
182
163
|
end
|
|
183
164
|
"""
|
|
184
|
-
When I run
|
|
185
|
-
Then the
|
|
165
|
+
When I run `rspec spec/views/secrets`
|
|
166
|
+
Then the examples should all pass
|
data/gemfiles/base.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module GemfileBase
|
|
2
|
+
def self.extended(host)
|
|
3
|
+
host.instance_eval do
|
|
4
|
+
source "http://rubygems.org"
|
|
5
|
+
|
|
6
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-rails].each do |lib|
|
|
7
|
+
library_path = File.expand_path("../../../#{lib}", __FILE__)
|
|
8
|
+
if File.exist?(library_path)
|
|
9
|
+
gem lib, :path => library_path
|
|
10
|
+
elsif ENV["CI"] || ENV["USE_GIT_REPOS"]
|
|
11
|
+
gem lib, :git => "git://github.com/rspec/#{lib}.git"
|
|
12
|
+
else
|
|
13
|
+
gem lib
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
gem 'sqlite3-ruby', :require => 'sqlite3'
|
|
18
|
+
gem "cucumber", "~> 0.10.2"
|
|
19
|
+
gem "aruba", "~> 0.3.6"
|
|
20
|
+
gem "growl", "1.0.3"
|
|
21
|
+
gem "ZenTest", "~> 4.4.2"
|
|
22
|
+
|
|
23
|
+
# gem "webrat", "0.7.3"
|
|
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
|
|
36
|
+
|
|
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
|
|
46
|
+
|
|
47
|
+
platforms :ruby_18, :ruby_19 do
|
|
48
|
+
gem "rb-fsevent", "~> 0.3.9"
|
|
49
|
+
gem "ruby-prof", "~> 0.9.2"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
platforms :jruby do
|
|
54
|
+
gem "jruby-openssl"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -71,7 +71,7 @@ class Autotest::RailsRspec2 < Autotest::Rspec2
|
|
|
71
71
|
add_mapping(%r%^config/database\.yml$%) { |_, m|
|
|
72
72
|
files_matching %r%^spec/models/.*_spec\.rb$%
|
|
73
73
|
}
|
|
74
|
-
add_mapping(%r%^(spec/(spec_helper|
|
|
74
|
+
add_mapping(%r%^(spec/(spec_helper|support/.*)|config/(boot|environment(s/test)?))\.rb$%) {
|
|
75
75
|
files_matching %r%^spec/(models|controllers|routing|views|helpers)/.*_spec\.rb$%
|
|
76
76
|
}
|
|
77
77
|
add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
|
|
@@ -9,16 +9,16 @@ module Rspec
|
|
|
9
9
|
class_option :controller_specs, :type => :boolean, :default => true
|
|
10
10
|
class_option :view_specs, :type => :boolean, :default => true
|
|
11
11
|
|
|
12
|
-
def
|
|
13
|
-
return unless options[:
|
|
12
|
+
def generate_controller_spec
|
|
13
|
+
return unless options[:controller_specs]
|
|
14
14
|
|
|
15
15
|
template 'controller_spec.rb',
|
|
16
16
|
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def
|
|
19
|
+
def generate_view_specs
|
|
20
20
|
return if actions.empty?
|
|
21
|
-
return unless options[:
|
|
21
|
+
return unless options[:view_specs]
|
|
22
22
|
|
|
23
23
|
empty_directory File.join("spec", "views", file_path)
|
|
24
24
|
|
|
@@ -3,10 +3,10 @@ require 'generators/rspec'
|
|
|
3
3
|
module Rspec
|
|
4
4
|
module Generators
|
|
5
5
|
class HelperGenerator < Base
|
|
6
|
-
class_option :
|
|
6
|
+
class_option :helper_specs, :type => :boolean, :default => true
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
return unless options[:
|
|
8
|
+
def generate_helper_spec
|
|
9
|
+
return unless options[:helper_specs]
|
|
10
10
|
|
|
11
11
|
template 'helper_spec.rb', File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
|
|
12
12
|
end
|
|
@@ -3,10 +3,24 @@ require 'generators/rspec'
|
|
|
3
3
|
module Rspec
|
|
4
4
|
module Generators
|
|
5
5
|
class IntegrationGenerator < Base
|
|
6
|
-
|
|
6
|
+
class_option :request_specs, :type => :boolean, :default => true, :desc => "Generate request specs"
|
|
7
|
+
class_option :webrat, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
|
|
8
|
+
class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
|
|
9
|
+
|
|
10
|
+
def generate_request_spec
|
|
11
|
+
return unless options[:request_specs]
|
|
12
|
+
|
|
7
13
|
template 'request_spec.rb',
|
|
8
14
|
File.join('spec/requests', class_path, "#{table_name}_spec.rb")
|
|
9
15
|
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def webrat?
|
|
20
|
+
RSpec.deprecate("the --webrat-matchers option", "--webrat") if options[:webrat_matchers]
|
|
21
|
+
options[:webrat] || options[:webrat_matchers]
|
|
22
|
+
end
|
|
23
|
+
|
|
10
24
|
end
|
|
11
25
|
end
|
|
12
26
|
end
|
|
@@ -3,7 +3,13 @@ require 'spec_helper'
|
|
|
3
3
|
describe "<%= class_name.pluralize %>" do
|
|
4
4
|
describe "GET /<%= table_name %>" do
|
|
5
5
|
it "works! (now write some real specs)" do
|
|
6
|
-
|
|
6
|
+
<% if webrat? -%>
|
|
7
|
+
visit <%= index_helper %>_path
|
|
8
|
+
<% else -%>
|
|
9
|
+
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
|
10
|
+
get <%= index_helper %>_path
|
|
11
|
+
<% end -%>
|
|
12
|
+
response.status.should be(200)
|
|
7
13
|
end
|
|
8
14
|
end
|
|
9
15
|
end
|
|
@@ -5,11 +5,11 @@ module Rspec
|
|
|
5
5
|
class MailerGenerator < Base
|
|
6
6
|
argument :actions, :type => :array, :default => [], :banner => "method method"
|
|
7
7
|
|
|
8
|
-
def
|
|
8
|
+
def generate_mailer_spec
|
|
9
9
|
template "mailer_spec.rb", File.join('spec/mailers', class_path, "#{file_name}_spec.rb")
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def
|
|
12
|
+
def generate_fixtures_files
|
|
13
13
|
actions.each do |action|
|
|
14
14
|
@action, @path = action, File.join(file_path, action)
|
|
15
15
|
template "fixture", File.join("spec/fixtures", @path)
|
|
@@ -6,7 +6,7 @@ module Rspec
|
|
|
6
6
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
|
7
7
|
class_option :fixture, :type => :boolean
|
|
8
8
|
|
|
9
|
-
def
|
|
9
|
+
def create_model_spec
|
|
10
10
|
template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -14,17 +14,19 @@ module Rspec
|
|
|
14
14
|
|
|
15
15
|
class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
|
|
16
16
|
class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
|
|
17
|
+
class_option :webrat, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
|
|
18
|
+
class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
|
|
17
19
|
class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs"
|
|
18
20
|
class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
|
|
19
21
|
|
|
20
|
-
def
|
|
22
|
+
def generate_controller_spec
|
|
21
23
|
return unless options[:controller_specs]
|
|
22
24
|
|
|
23
25
|
template 'controller_spec.rb',
|
|
24
26
|
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
def
|
|
29
|
+
def generate_view_specs
|
|
28
30
|
return unless options[:view_specs]
|
|
29
31
|
|
|
30
32
|
copy_view :edit
|
|
@@ -38,7 +40,7 @@ module Rspec
|
|
|
38
40
|
invoke invoked, [ controller_name ]
|
|
39
41
|
end
|
|
40
42
|
|
|
41
|
-
def
|
|
43
|
+
def generate_routing_spec
|
|
42
44
|
return unless options[:routing_specs]
|
|
43
45
|
|
|
44
46
|
template 'routing_spec.rb',
|
|
@@ -49,6 +51,11 @@ module Rspec
|
|
|
49
51
|
|
|
50
52
|
protected
|
|
51
53
|
|
|
54
|
+
def webrat?
|
|
55
|
+
RSpec.deprecate("--webrat-matchers", "--webrat") if options[:webrat_matchers]
|
|
56
|
+
options[:webrat] || options[:webrat_matchers]
|
|
57
|
+
end
|
|
58
|
+
|
|
52
59
|
def copy_view(view)
|
|
53
60
|
template "#{view}_spec.rb",
|
|
54
61
|
File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
|
@@ -58,6 +65,24 @@ module Rspec
|
|
|
58
65
|
"{'these' => 'params'}"
|
|
59
66
|
end
|
|
60
67
|
|
|
68
|
+
# support for namespaced-resources
|
|
69
|
+
def ns_file_name
|
|
70
|
+
if ARGV[0].match(/(\w+)\/(\w+)/)
|
|
71
|
+
"#{$1.underscore}_#{$2.singularize.underscore}"
|
|
72
|
+
else
|
|
73
|
+
file_name
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# support for namespaced-resources
|
|
78
|
+
def ns_table_name
|
|
79
|
+
if ARGV[0].match(/(\w+)\/(\w+)/)
|
|
80
|
+
"#{$1.underscore}/#{$2.tableize}"
|
|
81
|
+
else
|
|
82
|
+
table_name
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
61
86
|
# Returns the name of the mock. For example, if the file name is user,
|
|
62
87
|
# it returns mock_user.
|
|
63
88
|
#
|
|
@@ -74,9 +99,9 @@ module Rspec
|
|
|
74
99
|
if hash
|
|
75
100
|
method, and_return = hash.to_a.first
|
|
76
101
|
method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
|
|
77
|
-
"mock_#{
|
|
102
|
+
"mock_#{ns_file_name}(:#{method} => #{and_return})"
|
|
78
103
|
else
|
|
79
|
-
"mock_#{
|
|
104
|
+
"mock_#{ns_file_name}"
|
|
80
105
|
end
|
|
81
106
|
end
|
|
82
107
|
|
|
@@ -90,21 +115,21 @@ module Rspec
|
|
|
90
115
|
# should! orm_class.find(User, "37")
|
|
91
116
|
# #=> User.should_receive(:get).with(37)
|
|
92
117
|
#
|
|
93
|
-
def should_receive
|
|
118
|
+
def should_receive(chain)
|
|
94
119
|
stub_or_should_chain(:should_receive, chain)
|
|
95
120
|
end
|
|
96
121
|
|
|
97
122
|
# Receives the ORM chain and convert to stub. For ActiveRecord:
|
|
98
123
|
#
|
|
99
|
-
# stub
|
|
100
|
-
# #=> User.stub
|
|
124
|
+
# stub orm_class.find(User, "37")
|
|
125
|
+
# #=> User.stub(:find).with(37)
|
|
101
126
|
#
|
|
102
127
|
# For Datamapper:
|
|
103
128
|
#
|
|
104
|
-
# stub
|
|
105
|
-
# #=> User.stub
|
|
129
|
+
# stub orm_class.find(User, "37")
|
|
130
|
+
# #=> User.stub(:get).with(37)
|
|
106
131
|
#
|
|
107
|
-
def stub
|
|
132
|
+
def stub(chain)
|
|
108
133
|
stub_or_should_chain(:stub, chain)
|
|
109
134
|
end
|
|
110
135
|
|
|
@@ -126,6 +151,10 @@ module Rspec
|
|
|
126
151
|
end
|
|
127
152
|
end
|
|
128
153
|
|
|
154
|
+
def banner
|
|
155
|
+
self.class.banner
|
|
156
|
+
end
|
|
157
|
+
|
|
129
158
|
end
|
|
130
159
|
end
|
|
131
160
|
end
|