rspec-rails 1.2.9 → 1.3.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.
@@ -1,3 +1,9 @@
1
+ === Version 1.3.0 / 2010-01-11
2
+
3
+ * enhancements
4
+ * use stub() instead of stub!() in generators
5
+ * generate gem config in test.rb with 'script/generate rspec'
6
+
1
7
  === Version 1.2.9 / 2009-10-05
2
8
 
3
9
  * enhancements
@@ -15,6 +21,7 @@
15
21
  * no error if either action or template exist
16
22
  * error if neither exist
17
23
  * Closes #888.
24
+ * mock_model stubs destroyed? to return false
18
25
 
19
26
  * removals
20
27
  * spec_server has been removed in favor of spork.
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ Hoe.spec 'rspec-rails' do
15
15
  self.description = "Behaviour Driven Development for Ruby on Rails."
16
16
  self.rubyforge_name = 'rspec'
17
17
  self.developer 'RSpec Development Team', 'rspec-devel@rubyforge.org'
18
- self.extra_deps = [["rspec",">=1.2.9"],["rack",">=1.0.0"]]
18
+ self.extra_deps = [["rspec",">=1.3.0"],["rack",">=1.0.0"]]
19
19
  self.extra_dev_deps = [["cucumber",">= 0.3.99"]]
20
20
  self.remote_rdoc_dir = "rspec-rails/#{Spec::Rails::VERSION::STRING}"
21
21
  self.history_file = 'History.rdoc'
@@ -1,4 +1,4 @@
1
- = Upgrade to 1.2.8 (in git)
1
+ = Upgrade to 1.2.8/1.2.9/1.3.0
2
2
 
3
3
  == What's new
4
4
 
@@ -24,6 +24,26 @@ file so that it can be updated and you can manually restore your changes.
24
24
  HELPFUL_INSTRUCTIONS
25
25
  end
26
26
  Dir.mkdir('lib/tasks') unless File.directory?('lib/tasks')
27
+
28
+ if Rails::VERSION::STRING >= '2.1'
29
+ test_env = 'config/environments/test.rb'
30
+ contents = File.read(test_env)
31
+ unless contents =~ /config\.gem\s+(\"|\')rspec/m
32
+ puts "Configuring rspec and rspec-rails gems in #{test_env} ..."
33
+ puts
34
+ require File.expand_path('../../../lib/spec/rails/version.rb', __FILE__)
35
+ rspec_config = <<-EOF
36
+ config.gem 'rspec', :version => '>= #{Spec::Rails::VERSION::STRING}', :lib => false unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
37
+ config.gem 'rspec-rails', :version => '>= #{Spec::Rails::VERSION::STRING}', :lib => false unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
38
+ EOF
39
+ File.open(test_env, "wb") do |f|
40
+ f.puts contents
41
+ f.puts
42
+ f.puts rspec_config
43
+ end
44
+ end
45
+ end
46
+
27
47
  super
28
48
  end
29
49
 
@@ -41,7 +41,7 @@ Spec::Runner.configure do |config|
41
41
  #
42
42
  # == Mock Framework
43
43
  #
44
- # RSpec uses it's own mocking framework by default. If you prefer to
44
+ # RSpec uses its own mocking framework by default. If you prefer to
45
45
  # use mocha, flexmock or RR, uncomment the appropriate line:
46
46
  #
47
47
  # config.mock_with :mocha
@@ -8,7 +8,7 @@ describe <%= controller_class_name %>Controller do
8
8
 
9
9
  describe "GET index" do
10
10
  it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
11
- <%= class_name %>.stub!(:find).with(:all).and_return([mock_<%= file_name %>])
11
+ <%= class_name %>.stub(:find).with(:all).and_return([mock_<%= file_name %>])
12
12
  get :index
13
13
  assigns[:<%= table_name %>].should == [mock_<%= file_name %>]
14
14
  end
@@ -16,7 +16,7 @@ describe <%= controller_class_name %>Controller do
16
16
 
17
17
  describe "GET show" do
18
18
  it "assigns the requested <%= file_name %> as @<%= file_name %>" do
19
- <%= class_name %>.stub!(:find).with("37").and_return(mock_<%= file_name %>)
19
+ <%= class_name %>.stub(:find).with("37").and_return(mock_<%= file_name %>)
20
20
  get :show, :id => "37"
21
21
  assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
22
22
  end
@@ -24,7 +24,7 @@ describe <%= controller_class_name %>Controller do
24
24
 
25
25
  describe "GET new" do
26
26
  it "assigns a new <%= file_name %> as @<%= file_name %>" do
27
- <%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>)
27
+ <%= class_name %>.stub(:new).and_return(mock_<%= file_name %>)
28
28
  get :new
29
29
  assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
30
30
  end
@@ -32,7 +32,7 @@ describe <%= controller_class_name %>Controller do
32
32
 
33
33
  describe "GET edit" do
34
34
  it "assigns the requested <%= file_name %> as @<%= file_name %>" do
35
- <%= class_name %>.stub!(:find).with("37").and_return(mock_<%= file_name %>)
35
+ <%= class_name %>.stub(:find).with("37").and_return(mock_<%= file_name %>)
36
36
  get :edit, :id => "37"
37
37
  assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
38
38
  end
@@ -42,13 +42,13 @@ describe <%= controller_class_name %>Controller do
42
42
 
43
43
  describe "with valid params" do
44
44
  it "assigns a newly created <%= file_name %> as @<%= file_name %>" do
45
- <%= class_name %>.stub!(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
45
+ <%= class_name %>.stub(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
46
46
  post :create, :<%= file_name %> => {:these => 'params'}
47
47
  assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
48
48
  end
49
49
 
50
50
  it "redirects to the created <%= file_name %>" do
51
- <%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => true))
51
+ <%= class_name %>.stub(:new).and_return(mock_<%= file_name %>(:save => true))
52
52
  post :create, :<%= file_name %> => {}
53
53
  response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
54
54
  end
@@ -56,13 +56,13 @@ describe <%= controller_class_name %>Controller do
56
56
 
57
57
  describe "with invalid params" do
58
58
  it "assigns a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
59
- <%= class_name %>.stub!(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
59
+ <%= class_name %>.stub(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
60
60
  post :create, :<%= file_name %> => {:these => 'params'}
61
61
  assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
62
62
  end
63
63
 
64
64
  it "re-renders the 'new' template" do
65
- <%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => false))
65
+ <%= class_name %>.stub(:new).and_return(mock_<%= file_name %>(:save => false))
66
66
  post :create, :<%= file_name %> => {}
67
67
  response.should render_template('new')
68
68
  end
@@ -80,13 +80,13 @@ describe <%= controller_class_name %>Controller do
80
80
  end
81
81
 
82
82
  it "assigns the requested <%= file_name %> as @<%= file_name %>" do
83
- <%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
83
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
84
84
  put :update, :id => "1"
85
85
  assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
86
86
  end
87
87
 
88
88
  it "redirects to the <%= file_name %>" do
89
- <%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
89
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
90
90
  put :update, :id => "1"
91
91
  response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
92
92
  end
@@ -100,13 +100,13 @@ describe <%= controller_class_name %>Controller do
100
100
  end
101
101
 
102
102
  it "assigns the <%= file_name %> as @<%= file_name %>" do
103
- <%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
103
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
104
104
  put :update, :id => "1"
105
105
  assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
106
106
  end
107
107
 
108
108
  it "re-renders the 'edit' template" do
109
- <%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
109
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
110
110
  put :update, :id => "1"
111
111
  response.should render_template('edit')
112
112
  end
@@ -122,7 +122,7 @@ describe <%= controller_class_name %>Controller do
122
122
  end
123
123
 
124
124
  it "redirects to the <%= table_name %> list" do
125
- <%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:destroy => true))
125
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:destroy => true))
126
126
  delete :destroy, :id => "1"
127
127
  response.should redirect_to(<%= table_name %>_url)
128
128
  end
@@ -43,7 +43,7 @@ module Spec
43
43
  #
44
44
  class ControllerExampleGroup < FunctionalExampleGroup
45
45
  class << self
46
-
46
+
47
47
  # Use integrate_views to instruct RSpec to render views in
48
48
  # your controller examples in Integration mode.
49
49
  #
@@ -56,11 +56,11 @@ module Spec
56
56
  def integrate_views(integrate_views = true)
57
57
  @integrate_views = integrate_views
58
58
  end
59
-
59
+
60
60
  def integrate_views? # :nodoc:
61
61
  @integrate_views
62
62
  end
63
-
63
+
64
64
  def inherited(klass) # :nodoc:
65
65
  klass.integrate_views(integrate_views?)
66
66
  klass.subject { controller }
@@ -93,7 +93,7 @@ module Spec
93
93
  tests "#{name}_controller".camelize.constantize
94
94
  end
95
95
  end
96
-
96
+
97
97
  before(:each) do
98
98
  # Some Rails apps explicitly disable ActionMailer in environment.rb
99
99
  if defined?(ActionMailer)
@@ -107,7 +107,7 @@ Controller specs need to know what controller is being specified. You can
107
107
  indicate this by passing the controller to describe():
108
108
 
109
109
  describe MyController do
110
-
110
+
111
111
  or by declaring the controller's name
112
112
 
113
113
  describe "a MyController" do
@@ -121,7 +121,7 @@ MESSAGE
121
121
  end
122
122
 
123
123
  attr_reader :response, :request, :controller
124
-
124
+
125
125
  def integrate_views?
126
126
  @integrate_views || self.class.integrate_views?
127
127
  end
@@ -143,7 +143,7 @@ MESSAGE
143
143
  end
144
144
  end
145
145
  end
146
-
146
+
147
147
  protected
148
148
 
149
149
  def _assigns_hash_proxy
@@ -151,27 +151,33 @@ MESSAGE
151
151
  end
152
152
 
153
153
  private
154
-
154
+
155
155
  module TemplateIsolationExtensions
156
156
  def file_exists?(ignore); true; end
157
-
157
+
158
158
  def render_file(*args)
159
159
  @first_render ||= args[0] unless args[0] =~ /^layouts/
160
160
  end
161
-
161
+
162
162
  # Rails 2.2
163
163
  def _pick_template(*args)
164
164
  @_first_render ||= args[0] unless args[0] =~ /^layouts/
165
165
  PickedTemplate.new
166
166
  end
167
-
167
+
168
168
  def __action_exists?(params)
169
169
  controller.respond_to? params[:action]
170
170
  end
171
-
171
+
172
+ def __template_exists?(args)
173
+ self.view_paths.respond_to?(:find_template) ?
174
+ self.view_paths.find_template(args[0][:file], template_format) :
175
+ false
176
+ end
177
+
172
178
  def render(*args)
173
179
  if ::Rails::VERSION::STRING >= "2.1"
174
- return super unless __action_exists?(params)
180
+ return super unless __action_exists?(params) || __template_exists?(args)
175
181
  end
176
182
  if file = args.last[:file].instance_eval{@template_path}
177
183
  record_render :file => file
@@ -183,23 +189,24 @@ MESSAGE
183
189
  super
184
190
  end
185
191
  end
186
-
192
+
187
193
  private
188
-
194
+
189
195
  def record_render(opts)
190
- (@_rendered[:template] ||= opts[:file]) if opts[:file]
191
- (@_rendered[:partials][opts[:partial]] += 1) if opts[:partial]
196
+ return unless @_rendered
197
+ @_rendered[:template] ||= opts[:file] if opts[:file]
198
+ @_rendered[:partials][opts[:partial]] += 1 if opts[:partial]
192
199
  end
193
-
200
+
194
201
  # Returned by _pick_template when running controller examples in isolation mode.
195
- class PickedTemplate
202
+ class PickedTemplate
196
203
  # Do nothing when running controller examples in isolation mode.
197
204
  def render_template(*ignore_args); end
198
205
  # Do nothing when running controller examples in isolation mode.
199
206
  def render_partial(*ignore_args); end
200
207
  end
201
208
  end
202
-
209
+
203
210
  module ControllerInstanceMethods # :nodoc:
204
211
  include Spec::Rails::Example::RenderObserver
205
212
 
@@ -230,7 +237,7 @@ MESSAGE
230
237
  end
231
238
  end
232
239
  end
233
-
240
+
234
241
  # Rails 2.3
235
242
  def default_template(action_name = self.action_name)
236
243
  if integrate_views?
@@ -243,7 +250,7 @@ MESSAGE
243
250
  end
244
251
  end
245
252
  end
246
-
253
+
247
254
  def response(&block)
248
255
  # NOTE - we're setting @update for the assert_select_spec - kinda weird, huh?
249
256
  @update = block
@@ -255,7 +262,7 @@ MESSAGE
255
262
  end
256
263
 
257
264
  private
258
-
265
+
259
266
  def integrate_views?
260
267
  @integrate_views
261
268
  end
@@ -263,15 +270,15 @@ MESSAGE
263
270
  def matching_message_expectation_exists(options)
264
271
  render_proxy.__send__(:__mock_proxy).__send__(:find_matching_expectation, :render, options)
265
272
  end
266
-
273
+
267
274
  def matching_stub_exists(options)
268
275
  render_proxy.__send__(:__mock_proxy).__send__(:find_matching_method_stub, :render, options)
269
276
  end
270
-
277
+
271
278
  end
272
279
 
273
280
  Spec::Example::ExampleGroupFactory.register(:controller, self)
274
-
281
+
275
282
  end
276
283
  end
277
284
  end
@@ -38,7 +38,7 @@ module Spec
38
38
  @controller.__send__ :flash
39
39
  end
40
40
 
41
- # Provides acces to the session hash. Use this before or after
41
+ # Provides access to the session hash. Use this before or after
42
42
  # rendering a view, calling a helper or calling a controller action.
43
43
  def session
44
44
  request.session
@@ -6,7 +6,8 @@ module Spec
6
6
  # Model examples use Spec::Rails::Example::ModelExampleGroup, which
7
7
  # provides support for fixtures and some custom expectations via extensions
8
8
  # to ActiveRecord::Base.
9
- class ModelExampleGroup < ActiveSupport::TestCase
9
+ base = defined?(ActiveRecord::TestCase) ? ActiveRecord::TestCase : ActiveSupport::TestCase
10
+ class ModelExampleGroup < base
10
11
  Spec::Example::ExampleGroupFactory.register(:model, self)
11
12
  end
12
13
  end
@@ -1,46 +1,23 @@
1
1
  if defined?(ActiveRecord::Base)
2
- module Spec
3
- module Rails
4
- module Matchers
5
-
6
- class ArBeValid #:nodoc:
7
-
8
- def initialize
9
- @matcher = Spec::Matchers::Be.new :be_valid
10
- @matcher.__send__ :handling_predicate!
11
- end
12
-
13
- def matches?(actual)
14
- @actual = actual
15
- @matcher.matches? @actual
16
- end
17
-
18
- def failure_message_for_should
19
- if @actual.respond_to?(:errors) &&
20
- ActiveRecord::Errors === @actual.errors
21
- "Expected #{@actual.inspect} to be valid, but it was not\nErrors: " + @actual.errors.full_messages.join(", ")
22
- else
23
- @matcher.failure_message_for_should
24
- end
25
- end
26
-
27
- def failure_message_for_should_not
28
- @matcher.failure_message_for_should_not
29
- end
30
-
31
- def description
32
- "be valid"
33
- end
2
+ module Spec::Rails::Matchers
3
+ # :call-seq:
4
+ # response.should be_valid
5
+ # response.should_not be_valid
6
+ def be_valid
7
+ ::Spec::Matchers::Matcher.new :be_valid do
8
+ match do |actual|
9
+ actual.valid?
34
10
  end
35
11
 
36
- # :call-seq:
37
- # response.should be_valid
38
- # response.should_not be_valid
39
- def be_valid
40
- ArBeValid.new
12
+ failure_message_for_should do |actual|
13
+ if actual.respond_to?(:errors) && ActiveRecord::Errors === actual.errors
14
+ "Expected #{actual.inspect} to be valid, but it was not\nErrors: " + actual.errors.full_messages.join(", ")
15
+ else
16
+ "Expected #{actual.inspect} to be valid"
17
+ end
41
18
  end
42
-
43
19
  end
44
20
  end
21
+
45
22
  end
46
23
  end
@@ -14,6 +14,7 @@ module Spec
14
14
  :id => id,
15
15
  :to_param => id.to_s,
16
16
  :new_record? => false,
17
+ :destroyed? => false,
17
18
  :errors => stub("errors", :count => 0)
18
19
  })
19
20
  m = mock("#{model_class.name}_#{id}", options_and_stubs)
@@ -3,8 +3,8 @@ module Spec # :nodoc:
3
3
  module VERSION # :nodoc:
4
4
  unless defined? MAJOR
5
5
  MAJOR = 1
6
- MINOR = 2
7
- TINY = 9
6
+ MINOR = 3
7
+ TINY = 0
8
8
  PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -1,5 +1,6 @@
1
1
  <div id="session"><%= session[:key] %></div>
2
2
  <div id="params"><%= params[:key] %></div>
3
3
  <div id="flash"><%= flash[:key] %></div>
4
+ <div id="flash_now"><%= flash[:now_key] %></div>
4
5
  <div id="controller"><%= params[:controller] %></div>
5
6
  <div id="action"><%= params[:action] %></div>
@@ -6,6 +6,18 @@ module Spec
6
6
  describe ModelExampleGroup do
7
7
  accesses_configured_helper_methods
8
8
 
9
+ if defined?(ActiveRecord::TestCase)
10
+ it "derives from ActiveRecord::TestCase" do
11
+ group = describe("foo", :type => :model) do; end
12
+ group.ancestors.should include(ActiveRecord::TestCase)
13
+ end
14
+ else
15
+ it "derives from ActiveSupport::TestCase" do
16
+ group = describe("foo", :type => :model) do; end
17
+ group.ancestors.should include(ActiveSupport::TestCase)
18
+ end
19
+ end
20
+
9
21
  it "clears its name from the description" do
10
22
  group = describe("foo", :type => :model) do
11
23
  $nested_group = describe("bar") do
@@ -176,38 +176,35 @@ describe "A view", :type => :view do
176
176
  session[:key] = "session"
177
177
  params[:key] = "params"
178
178
  flash[:key] = "flash"
179
+ flash.now[:now_key] = "flash.now"
179
180
  render "view_spec/accessor"
180
181
  end
181
182
 
182
- it "should use the template as the implicit subject" do
183
+ it "uses the template as the implicit subject" do
183
184
  subject.should == template
184
185
  end
185
186
 
186
- describe "with a specified subject" do
187
- subject { 'specified' }
188
-
189
- it "should use the specified subject" do
190
- subject.should == 'specified'
191
- end
192
- end
193
-
194
- it "should have access to session data" do
187
+ it "has access to session data" do
195
188
  response.should have_tag("div#session", "session")
196
189
  end
197
190
 
198
- specify "should have access to params data" do
191
+ it "has access to params data" do
199
192
  response.should have_tag("div#params", "params")
200
193
  end
201
194
 
202
- it "should have access to flash data" do
195
+ it "has access to flash" do
203
196
  response.should have_tag("div#flash", "flash")
204
197
  end
205
198
 
206
- it "should have a controller param" do
199
+ it "has access to flash.now" do
200
+ response.should have_tag("div#flash_now", "flash.now")
201
+ end
202
+
203
+ it "has a controller param" do
207
204
  response.should have_tag("div#controller", "view_spec")
208
205
  end
209
206
 
210
- it "should have an action param" do
207
+ it "has an action param" do
211
208
  response.should have_tag("div#action", "accessor")
212
209
  end
213
210
  end
@@ -24,6 +24,9 @@ describe "mock_model" do
24
24
  it "should not say it instance_of? if it isn't, even if it's ancestor is" do
25
25
  @model.instance_of?(MockableModel).should be(false)
26
26
  end
27
+ it "should say it is not destroyed" do
28
+ @model.destroyed?(SubMockableModel).should be(false)
29
+ end
27
30
  end
28
31
 
29
32
  describe "with params" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RSpec Development Team
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-05 00:00:00 -05:00
12
+ date: 2010-01-11 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.9
23
+ version: 1.3.0
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
@@ -237,7 +237,7 @@ licenses: []
237
237
  post_install_message: |
238
238
  **************************************************
239
239
 
240
- Thank you for installing rspec-rails-1.2.9
240
+ Thank you for installing rspec-rails-1.3.0
241
241
 
242
242
  If you are upgrading, do this in each of your rails apps
243
243
  that you want to upgrade:
@@ -272,6 +272,6 @@ rubyforge_project: rspec
272
272
  rubygems_version: 1.3.5
273
273
  signing_key:
274
274
  specification_version: 3
275
- summary: rspec-rails 1.2.9
275
+ summary: rspec-rails 1.3.0
276
276
  test_files: []
277
277