rspec-rails 1.2.6 → 1.2.7

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.
Files changed (45) hide show
  1. data/History.rdoc +27 -2
  2. data/Manifest.txt +3 -2
  3. data/Rakefile +5 -6
  4. data/TODO.txt +17 -0
  5. data/Upgrade.rdoc +11 -0
  6. data/generators/integration_spec/integration_spec_generator.rb +10 -0
  7. data/generators/integration_spec/templates/integration_spec.rb +4 -0
  8. data/generators/rspec/templates/rcov.opts +1 -1
  9. data/generators/rspec/templates/rspec.rake +27 -12
  10. data/generators/rspec/templates/spec_helper.rb +5 -1
  11. data/generators/rspec_controller/templates/helper_spec.rb +1 -1
  12. data/generators/rspec_controller/templates/view_spec.rb +1 -1
  13. data/generators/rspec_default_values.rb +11 -2
  14. data/generators/rspec_model/templates/model_spec.rb +1 -3
  15. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +7 -3
  16. data/generators/rspec_scaffold/templates/controller_spec.rb +8 -8
  17. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +2 -4
  18. data/generators/rspec_scaffold/templates/helper_spec.rb +2 -2
  19. data/generators/rspec_scaffold/templates/index_erb_spec.rb +1 -2
  20. data/generators/rspec_scaffold/templates/new_erb_spec.rb +2 -4
  21. data/generators/rspec_scaffold/templates/routing_spec.rb +16 -16
  22. data/generators/rspec_scaffold/templates/show_erb_spec.rb +0 -1
  23. data/lib/autotest/discover.rb +5 -1
  24. data/lib/spec/rails.rb +0 -2
  25. data/lib/spec/rails/example.rb +1 -0
  26. data/lib/spec/rails/example/controller_example_group.rb +22 -2
  27. data/lib/spec/rails/example/functional_example_group.rb +22 -0
  28. data/lib/spec/rails/example/integration_example_group.rb +16 -0
  29. data/lib/spec/rails/example/render_observer.rb +15 -2
  30. data/lib/spec/rails/extensions/spec/matchers/have.rb +4 -4
  31. data/lib/spec/rails/matchers/ar_be_valid.rb +33 -31
  32. data/lib/spec/rails/matchers/change.rb +9 -7
  33. data/lib/spec/rails/matchers/render_template.rb +10 -1
  34. data/lib/spec/rails/spec_server.rb +3 -0
  35. data/lib/spec/rails/version.rb +4 -3
  36. data/spec/resources/controllers/controller_spec_controller.rb +5 -2
  37. data/spec/spec/rails/example/controller_isolation_spec.rb +7 -1
  38. data/spec/spec/rails/extensions/action_view_base_spec.rb +42 -16
  39. data/spec/spec/rails/matchers/errors_on_spec.rb +14 -2
  40. data/spec/spec/rails/matchers/have_text_spec.rb +0 -1
  41. data/spec/spec/rails/matchers/render_template_spec.rb +11 -1
  42. data/spec/spec/rails/spec_server_spec.rb +2 -1
  43. metadata +12 -11
  44. data/features/step_definitions/people.rb +0 -6
  45. data/features/support/env.rb +0 -13
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
5
5
  include <%= controller_class_name %>Helper
6
-
6
+
7
7
  before(:each) do
8
8
  assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
9
9
  :new_record? => false<%= output_attributes.empty? ? '' : ',' %>
@@ -15,7 +15,7 @@ describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
15
15
 
16
16
  it "renders the edit <%= file_name %> form" do
17
17
  render
18
-
18
+
19
19
  response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
20
20
  <% for attribute in output_attributes -%>
21
21
  with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
@@ -23,5 +23,3 @@ describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
23
23
  end
24
24
  end
25
25
  end
26
-
27
-
@@ -1,11 +1,11 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
2
2
 
3
3
  describe <%= controller_class_name %>Helper do
4
-
4
+
5
5
  #Delete this example and add some real ones or delete this file
6
6
  it "is included in the helper object" do
7
7
  included_modules = (class << helper; self; end).send :included_modules
8
8
  included_modules.should include(<%= controller_class_name %>Helper)
9
9
  end
10
-
10
+
11
11
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  describe "/<%= table_name %>/index.<%= default_file_extension %>" do
5
5
  include <%= controller_class_name %>Helper
6
-
6
+
7
7
  before(:each) do
8
8
  assigns[:<%= table_name %>] = [
9
9
  <% [1,2].each_with_index do |id, model_index| -%>
@@ -25,4 +25,3 @@ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
25
25
  <% end -%>
26
26
  end
27
27
  end
28
-
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  describe "/<%= table_name %>/new.<%= default_file_extension %>" do
5
5
  include <%= controller_class_name %>Helper
6
-
6
+
7
7
  before(:each) do
8
8
  assigns[:<%= file_name %>] = stub_model(<%= class_name %>,
9
9
  :new_record? => true<%= output_attributes.empty? ? '' : ',' %>
@@ -15,7 +15,7 @@ describe "/<%= table_name %>/new.<%= default_file_extension %>" do
15
15
 
16
16
  it "renders new <%= file_name %> form" do
17
17
  render
18
-
18
+
19
19
  response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
20
20
  <% for attribute in output_attributes -%>
21
21
  with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
@@ -23,5 +23,3 @@ describe "/<%= table_name %>/new.<%= default_file_extension %>" do
23
23
  end
24
24
  end
25
25
  end
26
-
27
-
@@ -5,27 +5,27 @@ describe <%= controller_class_name %>Controller do
5
5
  it "maps #index" do
6
6
  route_for(:controller => "<%= table_name %>", :action => "index").should == "/<%= table_name %>"
7
7
  end
8
-
8
+
9
9
  it "maps #new" do
10
10
  route_for(:controller => "<%= table_name %>", :action => "new").should == "/<%= table_name %>/new"
11
11
  end
12
-
12
+
13
13
  it "maps #show" do
14
14
  route_for(:controller => "<%= table_name %>", :action => "show", :id => "1").should == "/<%= table_name %>/1"
15
15
  end
16
-
16
+
17
17
  it "maps #edit" do
18
18
  route_for(:controller => "<%= table_name %>", :action => "edit", :id => "1").should == "/<%= table_name %>/1/edit"
19
19
  end
20
20
 
21
- it "maps #create" do
22
- route_for(:controller => "<%= table_name %>", :action => "create").should == {:path => "/<%= table_name %>", :method => :post}
23
- end
21
+ it "maps #create" do
22
+ route_for(:controller => "<%= table_name %>", :action => "create").should == {:path => "/<%= table_name %>", :method => :post}
23
+ end
24
+
25
+ it "maps #update" do
26
+ route_for(:controller => "<%= table_name %>", :action => "update", :id => "1").should == {:path =>"/<%= table_name %>/1", :method => :put}
27
+ end
24
28
 
25
- it "maps #update" do
26
- route_for(:controller => "<%= table_name %>", :action => "update", :id => "1").should == {:path =>"/<%= table_name %>/1", :method => :put}
27
- end
28
-
29
29
  it "maps #destroy" do
30
30
  route_for(:controller => "<%= table_name %>", :action => "destroy", :id => "1").should == {:path =>"/<%= table_name %>/1", :method => :delete}
31
31
  end
@@ -35,27 +35,27 @@ describe <%= controller_class_name %>Controller do
35
35
  it "generates params for #index" do
36
36
  params_from(:get, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "index"}
37
37
  end
38
-
38
+
39
39
  it "generates params for #new" do
40
40
  params_from(:get, "/<%= table_name %>/new").should == {:controller => "<%= table_name %>", :action => "new"}
41
41
  end
42
-
42
+
43
43
  it "generates params for #create" do
44
44
  params_from(:post, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "create"}
45
45
  end
46
-
46
+
47
47
  it "generates params for #show" do
48
48
  params_from(:get, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "show", :id => "1"}
49
49
  end
50
-
50
+
51
51
  it "generates params for #edit" do
52
52
  params_from(:get, "/<%= table_name %>/1/edit").should == {:controller => "<%= table_name %>", :action => "edit", :id => "1"}
53
53
  end
54
-
54
+
55
55
  it "generates params for #update" do
56
56
  params_from(:put, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "update", :id => "1"}
57
57
  end
58
-
58
+
59
59
  it "generates params for #destroy" do
60
60
  params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
61
61
  end
@@ -20,4 +20,3 @@ describe "/<%= table_name %>/show.<%= default_file_extension %>" do
20
20
  <% end -%>
21
21
  end
22
22
  end
23
-
@@ -1 +1,5 @@
1
- # This needs to be here for >= ZenTest-3.9.0 to add this directory to the load path.
1
+ Autotest.add_discovery do
2
+ style = []
3
+ style << "rails" if File.exist? 'config/environment.rb'
4
+ style
5
+ end
@@ -1,5 +1,3 @@
1
- RAILS_ENV ||= "test"
2
-
3
1
  begin
4
2
  require_dependency 'application_controller'
5
3
  rescue MissingSourceFile
@@ -9,6 +9,7 @@ require "spec/rails/example/controller_example_group"
9
9
  require "spec/rails/example/helper_example_group"
10
10
  require "spec/rails/example/view_example_group"
11
11
  require "spec/rails/example/routing_example_group"
12
+ require "spec/rails/example/integration_example_group"
12
13
  require "spec/rails/example/cookies_proxy"
13
14
 
14
15
  module Spec
@@ -166,8 +166,15 @@ MESSAGE
166
166
  end
167
167
 
168
168
  def render(*args)
169
- return super if Hash === args.last && args.last[:inline]
170
- @_rendered ? record_render(args[0]) : super
169
+ if file = args.last[:file].instance_eval{@template_path}
170
+ record_render :file => file
171
+ elsif args.last[:inline]
172
+ super
173
+ elsif @_rendered
174
+ record_render(args[0])
175
+ else
176
+ super
177
+ end
171
178
  end
172
179
 
173
180
  private
@@ -213,6 +220,19 @@ MESSAGE
213
220
  end
214
221
  end
215
222
 
223
+ # Rails 2.3
224
+ def default_template(action_name = self.action_name)
225
+ if integrate_views?
226
+ super
227
+ else
228
+ begin
229
+ super
230
+ rescue ActionView::MissingTemplate
231
+ "#{self.class.name.sub(/Controller$/,'').underscore}/#{action_name}"
232
+ end
233
+ end
234
+ end
235
+
216
236
  def response(&block)
217
237
  # NOTE - we're setting @update for the assert_select_spec - kinda weird, huh?
218
238
  @update = block
@@ -10,14 +10,36 @@ module Spec
10
10
 
11
11
  attr_reader :request, :response
12
12
 
13
+ # The params hash accessed within a view or helper. Use this before
14
+ # rendering a view or calling a helper to provide data used by the
15
+ # view or helper.
16
+ #
17
+ # == Examples
18
+ # # in a view spec
19
+ # params[:name] = "David"
20
+ # render
21
+ # response.should have_tag("div.name","David")
22
+ #
23
+ # # in a helper spec
24
+ # params[:first_name] = "David"
25
+ # params[:last_name] = "Chelimsky"
26
+ # helper.full_name.should == "David Chelimsky"
13
27
  def params
14
28
  request.parameters
15
29
  end
16
30
 
31
+ # Provides access to the flash hash. Use this after rendering a
32
+ # view, calling a helper or calling a controller action.
33
+ #
34
+ # == Examples
35
+ # post :create
36
+ # flash[:notice].should == "Success!"
17
37
  def flash
18
38
  @controller.__send__ :flash
19
39
  end
20
40
 
41
+ # Provides acces to the session hash. Use this before or after
42
+ # rendering a view, calling a helper or calling a controller action.
21
43
  def session
22
44
  request.session
23
45
  end
@@ -0,0 +1,16 @@
1
+ class ActionController::IntegrationTest
2
+ alias_method :orig_initialize, :initialize
3
+ def initialize(*args)
4
+ super
5
+ end
6
+ end
7
+
8
+ module Spec
9
+ module Rails
10
+ module Example
11
+ class IntegrationExampleGroup < ActionController::IntegrationTest
12
+ Spec::Example::ExampleGroupFactory.register(:integration, self)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -35,15 +35,28 @@ module Spec
35
35
  end
36
36
  end
37
37
 
38
+ def stub(*args)
39
+ if args[0] == :render
40
+ register_verify_after_each
41
+ render_proxy.stub(args.first, :expected_from => caller(1)[0])
42
+ else
43
+ super
44
+ end
45
+ end
46
+
47
+ # FIXME - for some reason, neither alias nor alias_method are working
48
+ # as expected in the else branch, so this is a duplicate of stub()
49
+ # above. Could delegate, but then we'd run into craziness handling
50
+ # :expected_from. This will have to do for the moment.
38
51
  def stub!(*args)
39
52
  if args[0] == :render
40
53
  register_verify_after_each
41
- render_proxy.stub!(:render, :expected_from => caller(1)[0])
54
+ render_proxy.stub!(args.first, :expected_from => caller(1)[0])
42
55
  else
43
56
  super
44
57
  end
45
58
  end
46
-
59
+
47
60
  def verify_rendered_proc #:nodoc:
48
61
  template = self
49
62
  @verify_rendered_proc ||= Proc.new do
@@ -6,14 +6,14 @@ module Spec #:nodoc:
6
6
 
7
7
  def failure_message_for_should_with_errors_on_extensions
8
8
  return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
9
- return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
10
- return failure_message_without_errors_on_extensions
9
+ return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
10
+ return failure_message_for_should_without_errors_on_extensions
11
11
  end
12
12
  alias_method_chain :failure_message_for_should, :errors_on_extensions
13
13
 
14
14
  def description_with_errors_on_extensions
15
- return "should have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
16
- return "should have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
15
+ return "have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
16
+ return "have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
17
17
  return description_without_errors_on_extensions
18
18
  end
19
19
  alias_method_chain :description, :errors_on_extensions
@@ -1,44 +1,46 @@
1
- module Spec
2
- module Rails
3
- module Matchers
1
+ if defined?(ActiveRecord::Base)
2
+ module Spec
3
+ module Rails
4
+ module Matchers
4
5
 
5
- class ArBeValid #:nodoc:
6
+ class ArBeValid #:nodoc:
6
7
 
7
- def initialize
8
- @matcher = Spec::Matchers::Be.new :be_valid
9
- @matcher.__send__ :handling_predicate!
10
- end
8
+ def initialize
9
+ @matcher = Spec::Matchers::Be.new :be_valid
10
+ @matcher.__send__ :handling_predicate!
11
+ end
11
12
 
12
- def matches?(actual)
13
- @actual = actual
14
- @matcher.matches? @actual
15
- end
13
+ def matches?(actual)
14
+ @actual = actual
15
+ @matcher.matches? @actual
16
+ end
16
17
 
17
- def failure_message_for_should
18
- if @actual.respond_to?(:errors) &&
19
- ActiveRecord::Errors === @actual.errors
20
- "Expected #{@actual.inspect} to be valid, but it was not\nErrors: " + @actual.errors.full_messages.join(", ")
21
- else
22
- @matcher.failure_message_for_should
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
23
25
  end
24
- end
25
26
 
26
- def failure_message_for_should_not
27
- @matcher.failure_message_for_should_not
28
- end
27
+ def failure_message_for_should_not
28
+ @matcher.failure_message_for_should_not
29
+ end
29
30
 
30
- def description
31
- "be valid"
31
+ def description
32
+ "be valid"
33
+ end
32
34
  end
33
- end
34
35
 
35
- # :call-seq:
36
- # response.should be_valid
37
- # response.should_not be_valid
38
- def be_valid
39
- ArBeValid.new
40
- end
36
+ # :call-seq:
37
+ # response.should be_valid
38
+ # response.should_not be_valid
39
+ def be_valid
40
+ ArBeValid.new
41
+ end
41
42
 
43
+ end
42
44
  end
43
45
  end
44
46
  end
@@ -1,11 +1,13 @@
1
- module Spec
2
- module Matchers
3
- class Change
4
- def evaluate_value_proc_with_ensured_evaluation_of_proxy
5
- value = evaluate_value_proc_without_ensured_evaluation_of_proxy
6
- ActiveRecord::Associations::AssociationProxy === value ? value.dup : value
1
+ if defined?(ActiveRecord::Base)
2
+ module Spec
3
+ module Matchers
4
+ class Change
5
+ def evaluate_value_proc_with_ensured_evaluation_of_proxy
6
+ value = evaluate_value_proc_without_ensured_evaluation_of_proxy
7
+ ActiveRecord::Associations::AssociationProxy === value ? value.dup : value
8
+ end
9
+ alias_method_chain :evaluate_value_proc, :ensured_evaluation_of_proxy
7
10
  end
8
- alias_method_chain :evaluate_value_proc, :ensured_evaluation_of_proxy
9
11
  end
10
12
  end
11
13
  end
@@ -33,7 +33,16 @@ module Spec
33
33
  return false if @actual.blank?
34
34
  given_controller_path, given_file = path_and_file(@actual)
35
35
  expected_controller_path, expected_file = path_and_file(@expected)
36
- given_controller_path == expected_controller_path && given_file.match(expected_file)
36
+ given_controller_path == expected_controller_path && match_files(given_file, expected_file)
37
+ end
38
+
39
+ def match_files(actual, expected)
40
+ actual_parts = actual.split('.')
41
+ expected_parts = expected.split('.')
42
+ expected_parts.each_with_index do |expected_part, index|
43
+ return false unless expected_part == actual_parts[index]
44
+ end
45
+ true
37
46
  end
38
47
 
39
48
  def failure_message_for_should
@@ -1,3 +1,6 @@
1
+ require 'spec/deprecation'
2
+ Spec.deprecate('spec_server', 'spork (gem install spork)')
3
+
1
4
  if Rails::VERSION::STRING >= '2.2' && Rails.configuration.cache_classes
2
5
  raise <<-MESSAGE
3
6