rspec-rails 2.5.0 → 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.
Files changed (90) hide show
  1. data/.gitignore +10 -5
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/README.md +2 -0
  5. data/README_DEV.md +43 -0
  6. data/Rakefile +72 -31
  7. data/Thorfile +33 -18
  8. data/features/.nav +2 -0
  9. data/features/Autotest.md +7 -0
  10. data/features/Changelog.md +26 -2
  11. data/features/Generators.md +1 -1
  12. data/features/GettingStarted.md +45 -1
  13. data/features/Upgrade.md +13 -12
  14. data/features/controller_specs/README.md +18 -10
  15. data/features/controller_specs/anonymous_controller.feature +5 -5
  16. data/features/controller_specs/controller_spec.feature +1 -2
  17. data/features/controller_specs/isolation_from_views.feature +49 -3
  18. data/features/controller_specs/render_views.feature +3 -3
  19. data/features/helper_specs/helper_spec.feature +3 -3
  20. data/features/mailer_specs/url_helpers.feature +2 -2
  21. data/features/matchers/new_record_matcher.feature +1 -43
  22. data/features/matchers/redirect_to_matcher.feature +3 -3
  23. data/features/matchers/render_template_matcher.feature +12 -9
  24. data/features/mocks/mock_model.feature +21 -5
  25. data/features/mocks/stub_model.feature +2 -2
  26. data/features/model_specs/errors_on.feature +1 -1
  27. data/features/model_specs/transactional_examples.feature +10 -5
  28. data/features/request_specs/request_spec.feature +49 -0
  29. data/features/routing_specs/README.md +2 -1
  30. data/features/routing_specs/be_routable_matcher.feature +5 -5
  31. data/features/routing_specs/named_routes.feature +1 -1
  32. data/features/routing_specs/route_to_matcher.feature +28 -8
  33. data/features/step_definitions/additional_cli_steps.rb +1 -1
  34. data/features/support/env.rb +7 -19
  35. data/features/view_specs/inferred_controller_path.feature +3 -3
  36. data/features/view_specs/stub_template.feature +2 -2
  37. data/features/view_specs/view_spec.feature +16 -35
  38. data/gemfiles/.bundle/config +2 -0
  39. data/gemfiles/base.rb +58 -0
  40. data/gemfiles/rails-3-0-stable +6 -0
  41. data/gemfiles/rails-3.0.0 +5 -0
  42. data/gemfiles/rails-3.0.1 +5 -0
  43. data/gemfiles/rails-3.0.2 +5 -0
  44. data/gemfiles/rails-3.0.3 +5 -0
  45. data/gemfiles/rails-3.0.4 +5 -0
  46. data/gemfiles/rails-3.0.5 +5 -0
  47. data/gemfiles/rails-3.0.6 +5 -0
  48. data/gemfiles/rails-3.0.7 +5 -0
  49. data/gemfiles/rails-3.1.0.beta1 +5 -0
  50. data/gemfiles/rails-master +7 -0
  51. data/lib/generators/rspec/scaffold/scaffold_generator.rb +20 -2
  52. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +86 -54
  53. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +7 -7
  54. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  55. data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -5
  56. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
  57. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  58. data/lib/rspec/rails/example/controller_example_group.rb +12 -22
  59. data/lib/rspec/rails/example/helper_example_group.rb +0 -5
  60. data/lib/rspec/rails/example/mailer_example_group.rb +0 -9
  61. data/lib/rspec/rails/example/request_example_group.rb +0 -25
  62. data/lib/rspec/rails/example/routing_example_group.rb +1 -0
  63. data/lib/rspec/rails/example/view_example_group.rb +7 -6
  64. data/lib/rspec/rails/matchers/routing_matchers.rb +23 -2
  65. data/lib/rspec/rails/mocks.rb +3 -0
  66. data/lib/rspec/rails/tasks/rspec.rake +1 -1
  67. data/lib/rspec/rails/vendor/capybara.rb +29 -0
  68. data/lib/rspec/rails/vendor/webrat.rb +33 -0
  69. data/lib/rspec/rails/version.rb +1 -1
  70. data/lib/rspec/rails/view_rendering.rb +24 -8
  71. data/lib/rspec/rails.rb +2 -2
  72. data/rspec-rails.gemspec +5 -36
  73. data/spec/autotest/rails_rspec2_spec.rb +2 -7
  74. data/spec/rspec/rails/example/controller_example_group_spec.rb +25 -0
  75. data/spec/rspec/rails/matchers/route_to_spec.rb +15 -0
  76. data/spec/rspec/rails/mocks/ar_classes.rb +5 -2
  77. data/spec/rspec/rails/view_rendering_spec.rb +0 -6
  78. data/spec/spec_helper.rb +0 -22
  79. data/spec/support/matchers.rb +9 -0
  80. data/templates/generate_stuff.rb +9 -1
  81. data/templates/run_specs.rb +2 -2
  82. metadata +44 -65
  83. data/Gemfile-3-0-stable +0 -6
  84. data/Gemfile-3.0.0 +0 -3
  85. data/Gemfile-3.0.3 +0 -3
  86. data/Gemfile-base +0 -38
  87. data/Gemfile-master +0 -5
  88. data/lib/rspec/rails/browser_simulators.rb +0 -30
  89. data/specs.watchr +0 -59
  90. data/templates/Gemfile-base +0 -17
@@ -4,33 +4,33 @@ describe <%= controller_class_name %>Controller do
4
4
  describe "routing" do
5
5
 
6
6
  <% unless options[:singleton] -%>
7
- it "recognizes and generates #index" do
8
- { :get => "/<%= table_name %>" }.should route_to(:controller => "<%= table_name %>", :action => "index")
7
+ it "routes to #index" do
8
+ get("/<%= ns_table_name %>").should route_to("<%= ns_table_name %>#index")
9
9
  end
10
10
 
11
11
  <% end -%>
12
- it "recognizes and generates #new" do
13
- { :get => "/<%= table_name %>/new" }.should route_to(:controller => "<%= table_name %>", :action => "new")
12
+ it "routes to #new" do
13
+ get("/<%= ns_table_name %>/new").should route_to("<%= ns_table_name %>#new")
14
14
  end
15
15
 
16
- it "recognizes and generates #show" do
17
- { :get => "/<%= table_name %>/1" }.should route_to(:controller => "<%= table_name %>", :action => "show", :id => "1")
16
+ it "routes to #show" do
17
+ get("/<%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#show", :id => "1")
18
18
  end
19
19
 
20
- it "recognizes and generates #edit" do
21
- { :get => "/<%= table_name %>/1/edit" }.should route_to(:controller => "<%= table_name %>", :action => "edit", :id => "1")
20
+ it "routes to #edit" do
21
+ get("/<%= ns_table_name %>/1/edit").should route_to("<%= ns_table_name %>#edit", :id => "1")
22
22
  end
23
23
 
24
- it "recognizes and generates #create" do
25
- { :post => "/<%= table_name %>" }.should route_to(:controller => "<%= table_name %>", :action => "create")
24
+ it "routes to #create" do
25
+ post("/<%= ns_table_name %>").should route_to("<%= ns_table_name %>#create")
26
26
  end
27
27
 
28
- it "recognizes and generates #update" do
29
- { :put => "/<%= table_name %>/1" }.should route_to(:controller => "<%= table_name %>", :action => "update", :id => "1")
28
+ it "routes to #update" do
29
+ put("/<%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#update", :id => "1")
30
30
  end
31
31
 
32
- it "recognizes and generates #destroy" do
33
- { :delete => "/<%= table_name %>/1" }.should route_to(:controller => "<%= table_name %>", :action => "destroy", :id => "1")
32
+ it "routes to #destroy" do
33
+ delete("/<%= ns_table_name %>/1").should route_to("<%= ns_table_name %>#destroy", :id => "1")
34
34
  end
35
35
 
36
36
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
- describe "<%= table_name %>/show.html.<%= options[:template_engine] %>" do
4
+ describe "<%= ns_table_name %>/show.html.<%= options[:template_engine] %>" do
5
5
  before(:each) do
6
- @<%= file_name %> = assign(:<%= file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
7
7
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
8
  :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
9
  <% end -%>
@@ -82,16 +82,6 @@ module RSpec::Rails
82
82
  include RSpec::Rails::Matchers::RedirectTo
83
83
  include RSpec::Rails::Matchers::RenderTemplate
84
84
  include RSpec::Rails::Matchers::RoutingMatchers
85
- include RSpec::Rails::BrowserSimulators
86
-
87
- webrat do
88
- include Webrat::Matchers
89
- include Webrat::Methods
90
- end
91
-
92
- capybara do
93
- include Capybara
94
- end
95
85
 
96
86
  module ClassMethods
97
87
  def controller_class
@@ -135,11 +125,9 @@ module RSpec::Rails
135
125
  # defined in +ApplicationController+, however, are accessible from within
136
126
  # the block.
137
127
  def controller(base_class = ApplicationController, &body)
138
- metadata[:example_group][:describes] = Class.new(base_class, &body)
139
- metadata[:example_group][:describes].singleton_class.class_eval do
140
- def name
141
- "StubResourcesController"
142
- end
128
+ base_class.dup.tap do |new_base|
129
+ def new_base.name; "StubResourcesController"; end
130
+ metadata[:example_group][:describes] = Class.new(new_base, &body)
143
131
  end
144
132
 
145
133
  before do
@@ -148,13 +136,21 @@ module RSpec::Rails
148
136
  end
149
137
 
150
138
  after do
151
- @routes = @orig_routes
139
+ @routes, @orig_routes = @orig_routes, nil
152
140
  end
153
141
  end
154
142
  end
155
143
 
156
144
  module InstanceMethods
157
145
  attr_reader :controller, :routes
146
+
147
+ def method_missing(method, *args, &block)
148
+ if @orig_routes && @orig_routes.named_routes.helpers.include?(method)
149
+ controller.send(method, *args, &block)
150
+ else
151
+ super
152
+ end
153
+ end
158
154
  end
159
155
 
160
156
  included do
@@ -166,12 +162,6 @@ module RSpec::Rails
166
162
  @routes = ::Rails.application.routes
167
163
  ActionController::Base.allow_forgery_protection = false
168
164
  end
169
-
170
- webrat do
171
- before do
172
- Webrat.configure {|c| c.mode = :rails}
173
- end
174
- end
175
165
  end
176
166
  end
177
167
  end
@@ -30,11 +30,6 @@ module RSpec::Rails
30
30
  include RSpec::Rails::RailsExampleGroup
31
31
  include ActionView::TestCase::Behavior
32
32
  include RSpec::Rails::ViewAssigns
33
- include RSpec::Rails::BrowserSimulators
34
-
35
- webrat do
36
- include Webrat::Matchers
37
- end
38
33
 
39
34
  module ClassMethods
40
35
  def determine_default_helper_class(ignore)
@@ -4,15 +4,6 @@ if defined?(ActionMailer)
4
4
  extend ActiveSupport::Concern
5
5
  include RSpec::Rails::RailsExampleGroup
6
6
  include ActionMailer::TestCase::Behavior
7
- include RSpec::Rails::BrowserSimulators
8
-
9
- webrat do
10
- include Webrat::Matchers
11
- end
12
-
13
- capybara do
14
- include Capybara
15
- end
16
7
 
17
8
  included do
18
9
  metadata[:type] = :mailer
@@ -16,7 +16,6 @@ module RSpec::Rails
16
16
  include RSpec::Rails::RailsExampleGroup
17
17
  include ActionDispatch::Integration::Runner
18
18
  include ActionDispatch::Assertions
19
- include RSpec::Rails::BrowserSimulators
20
19
 
21
20
  module InstanceMethods
22
21
  def app
@@ -24,22 +23,6 @@ module RSpec::Rails
24
23
  end
25
24
  end
26
25
 
27
- webrat do
28
- include Webrat::Matchers
29
- include Webrat::Methods
30
-
31
- module InstanceMethods
32
-
33
- def last_response
34
- @response
35
- end
36
- end
37
- end
38
-
39
- capybara do
40
- include Capybara
41
- end
42
-
43
26
  include RSpec::Rails::Matchers::RedirectTo
44
27
  include RSpec::Rails::Matchers::RenderTemplate
45
28
  include ActionController::TemplateAssertions
@@ -50,14 +33,6 @@ module RSpec::Rails
50
33
  before do
51
34
  @routes = ::Rails.application.routes
52
35
  end
53
-
54
- webrat do
55
- before do
56
- Webrat.configure do |c|
57
- c.mode = :rack
58
- end
59
- end
60
- end
61
36
  end
62
37
  end
63
38
  end
@@ -6,6 +6,7 @@ module RSpec::Rails
6
6
  include RSpec::Rails::RailsExampleGroup
7
7
  include ActionDispatch::Assertions::RoutingAssertions
8
8
  include RSpec::Rails::Matchers::RoutingMatchers
9
+ include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
9
10
 
10
11
  module InstanceMethods
11
12
  attr_reader :routes
@@ -23,11 +23,6 @@ module RSpec::Rails
23
23
  include ActionView::TestCase::Behavior
24
24
  include RSpec::Rails::ViewAssigns
25
25
  include RSpec::Rails::Matchers::RenderTemplate
26
- include RSpec::Rails::BrowserSimulators
27
-
28
- webrat do
29
- include Webrat::Matchers
30
- end
31
26
 
32
27
  module ClassMethods
33
28
  def _default_helper
@@ -147,7 +142,13 @@ module RSpec::Rails
147
142
 
148
143
  before do
149
144
  _include_controller_helpers
150
- controller.controller_path = _controller_path
145
+ if view.lookup_context.respond_to?(:prefixes)
146
+ # rails 3.1
147
+ view.lookup_context.prefixes << _controller_path
148
+ else
149
+ # rails 3.0
150
+ controller.controller_path = _controller_path
151
+ end
151
152
  controller.request.path_parameters["controller"] = _controller_path
152
153
  controller.request.path_parameters["action"] = _inferred_action unless _inferred_action =~ /^_/
153
154
  end
@@ -2,10 +2,21 @@ module RSpec::Rails::Matchers
2
2
  module RoutingMatchers
3
3
  extend RSpec::Matchers::DSL
4
4
 
5
- matcher :route_to do |route_options|
5
+ matcher :route_to do |*route_options|
6
6
  match_unless_raises ActiveSupport::TestCase::Assertion do |path|
7
7
  assertion_path = { :method => path.keys.first, :path => path.values.first }
8
- assert_recognizes(route_options, assertion_path)
8
+
9
+ path, options = *route_options
10
+
11
+ if path.is_a?(String)
12
+ controller, action = path.split("#")
13
+ options ||= {}
14
+ options.merge!(:controller => controller, :action => action)
15
+ else
16
+ options = path
17
+ end
18
+
19
+ assert_recognizes(options, assertion_path)
9
20
  end
10
21
 
11
22
  failure_message_for_should do
@@ -24,5 +35,15 @@ module RSpec::Rails::Matchers
24
35
  "expected #{path.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
25
36
  end
26
37
  end
38
+
39
+ module RouteHelpers
40
+
41
+ %w(get post put delete options head).each do |method|
42
+ define_method method do |path|
43
+ { method.to_sym => path }
44
+ end
45
+ end
46
+
47
+ end
27
48
  end
28
49
  end
@@ -1,3 +1,6 @@
1
+ require 'active_support/core_ext'
2
+ require 'active_model'
3
+
1
4
  module RSpec
2
5
  module Rails
3
6
 
@@ -41,7 +41,7 @@ namespace :spec do
41
41
  ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
42
42
  ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
43
43
  ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
44
- ::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailer')
44
+ ::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailers')
45
45
  ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
46
46
  ::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests')
47
47
  end
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'capybara/rspec'
3
+ rescue LoadError
4
+ end
5
+
6
+ begin
7
+ require 'capybara/rails'
8
+ rescue LoadError
9
+ end
10
+
11
+ RSpec.configure do |c|
12
+ if defined?(Capybara::RSpecMatchers)
13
+ c.include Capybara::RSpecMatchers, :type => :view
14
+ c.include Capybara::RSpecMatchers, :type => :helper
15
+ c.include Capybara::RSpecMatchers, :type => :mailer
16
+ c.include Capybara::RSpecMatchers, :type => :controller
17
+ end
18
+
19
+ if defined?(Capybara::DSL)
20
+ c.include Capybara::DSL, :type => :controller
21
+ end
22
+
23
+ unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
24
+ if defined?(Capybara)
25
+ c.include Capybara, :type => :request
26
+ c.include Capybara, :type => :controller
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'webrat'
3
+ rescue LoadError
4
+ end
5
+
6
+ RSpec.configure do |c|
7
+ if defined?(Webrat)
8
+ c.include Webrat::Matchers, :type => :request
9
+ c.include Webrat::Matchers, :type => :controller
10
+ c.include Webrat::Matchers, :type => :view
11
+ c.include Webrat::Matchers, :type => :helper
12
+ c.include Webrat::Matchers, :type => :mailer
13
+
14
+ c.include Webrat::Methods, :type => :request
15
+ c.include Webrat::Methods, :type => :controller
16
+
17
+ module RequestInstanceMethods
18
+ def last_response
19
+ @response
20
+ end
21
+ end
22
+
23
+ c.include RequestInstanceMethods, :type => :request
24
+
25
+ c.before :type => :controller do
26
+ Webrat.configure {|c| c.mode = :rails}
27
+ end
28
+
29
+ c.before :type => :request do
30
+ Webrat.configure {|c| c.mode = :rack}
31
+ end
32
+ end
33
+ end
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Rails # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.5.0'
4
+ STRING = '2.6.0'
5
5
  end
6
6
  end
7
7
  end
@@ -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 PathSetDelegatorResolver < ::ActionView::Resolver
53
- attr_reader :path_set
52
+ class EmptyTemplatePathSetDecorator < ::ActionView::Resolver
53
+ attr_reader :original_path_set
54
54
 
55
- def initialize(path_set)
56
- @path_set = path_set
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
- path_set.find_all(*args).collect do |template|
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
- @_path_set_delegator_resolver = PathSetDelegatorResolver.new(controller.class.view_paths)
78
- controller.class.view_paths = ::ActionView::PathSet.new.push(@_path_set_delegator_resolver)
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 = @_path_set_delegator_resolver.path_set
100
+ controller.class.view_paths = @_empty_view_path_set_delegator.original_path_set
85
101
  end
86
102
  end
87
103
  end
data/lib/rspec/rails.rb CHANGED
@@ -12,6 +12,6 @@ require 'rspec/rails/matchers'
12
12
  require 'rspec/rails/fixture_support'
13
13
  require 'rspec/rails/mocks'
14
14
  require 'rspec/rails/module_inclusion'
15
- require 'rspec/rails/browser_simulators'
16
15
  require 'rspec/rails/example'
17
-
16
+ require 'rspec/rails/vendor/capybara'
17
+ require 'rspec/rails/vendor/webrat'
data/rspec-rails.gemspec CHANGED
@@ -22,44 +22,13 @@ Gem::Specification.new do |s|
22
22
  s.rdoc_options = ["--charset=UTF-8"]
23
23
  s.require_path = "lib"
24
24
 
25
- s.post_install_message = %Q{**************************************************
26
-
27
- Thank you for installing #{s.summary}!
28
-
29
- This version of rspec-rails only works with versions of rails >= 3.0.0
30
-
31
- To configure your app to use rspec-rails, add a declaration to your Gemfile.
32
- If you are using Bundler's grouping feature in your Gemfile, be sure to include
33
- rspec-rails in the :development group as well as the :test group so that you
34
- can access its generators and rake tasks.
35
-
36
- group :development, :test do
37
- gem "rspec-rails", ">= #{RSpec::Rails::Version::STRING}"
38
- end
39
-
40
- Be sure to run the following command in each of your Rails apps if you're
41
- upgrading:
42
-
43
- script/rails generate rspec:install
44
-
45
- Even if you've run it before, this ensures that you have the latest updates
46
- to spec/spec_helper.rb and any other support files.
47
-
48
- Beta versions of rspec-rails-2 installed files that are no longer being used,
49
- so please remove these files if you have them:
50
-
51
- lib/tasks/rspec.rake
52
- config/initializers/rspec_generator.rb
53
-
54
- Lastly, be sure to look at Upgrade.markdown to see what might have changed
55
- since the last release.
56
-
57
- **************************************************
58
- }
59
-
60
25
  s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
61
26
  s.add_runtime_dependency(%q<actionpack>, ["~> 3.0"])
62
27
  s.add_runtime_dependency(%q<railties>, ["~> 3.0"])
63
- s.add_runtime_dependency "rspec", "~> #{RSpec::Rails::Version::STRING.split('.')[0..1].concat(['0']).join('.')}"
28
+ if RSpec::Rails::Version::STRING =~ /[a-zA-Z]+/
29
+ s.add_runtime_dependency "rspec", "= #{RSpec::Rails::Version::STRING}"
30
+ else
31
+ s.add_runtime_dependency "rspec", "~> #{RSpec::Rails::Version::STRING.split('.')[0..1].concat(['0']).join('.')}"
32
+ end
64
33
  end
65
34
 
@@ -26,16 +26,11 @@ describe Autotest::RailsRspec2 do
26
26
  end
27
27
 
28
28
  describe 'mappings' do
29
- before do
30
- rails_rspec2_autotest.find_order = %w(
31
- spec/models/user_spec.rb
32
- spec/support/blueprints.rb
33
- )
34
- end
35
-
36
29
  it 'runs model specs when support files change' do
30
+ rails_rspec2_autotest.find_order = %w(spec/models/user_spec.rb spec/support/blueprints.rb)
37
31
  rails_rspec2_autotest.test_files_for('spec/support/blueprints.rb').should(
38
32
  include('spec/models/user_spec.rb'))
39
33
  end
40
34
  end
35
+
41
36
  end
@@ -35,5 +35,30 @@ module RSpec::Rails
35
35
  example.subject.should == 'explicit'
36
36
  end
37
37
  end
38
+
39
+ describe "with anonymous controller" do
40
+ before do
41
+ group.class_eval do
42
+ controller(Class.new) { }
43
+ end
44
+ end
45
+
46
+ it "delegates named route helpers to the underlying controller" do
47
+ controller = double('controller')
48
+ controller.stub(:foos_url).and_return('http://test.host/foos')
49
+
50
+ example = group.new
51
+ example.stub(:controller => controller)
52
+
53
+ # As in the routing example spec, this is pretty invasive, but not sure
54
+ # how to do it any other way as the correct operation relies on before
55
+ # hooks
56
+ routes = ActionDispatch::Routing::RouteSet.new
57
+ routes.draw { resources :foos }
58
+ example.instance_variable_set(:@orig_routes, routes)
59
+
60
+ example.foos_url.should eq('http://test.host/foos')
61
+ end
62
+ end
38
63
  end
39
64
  end
@@ -2,12 +2,27 @@ require "spec_helper"
2
2
 
3
3
  describe "route_to" do
4
4
  include RSpec::Rails::Matchers::RoutingMatchers
5
+ include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
5
6
 
6
7
  it "delegates to assert_recognizes" do
7
8
  self.should_receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" })
8
9
  {:get => "path"}.should route_to("these" => "options")
9
10
  end
10
11
 
12
+ context "with shortcut syntax" do
13
+
14
+ it "routes with extra options" do
15
+ self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" })
16
+ get("path").should route_to("controller#action", :extra => "options")
17
+ end
18
+
19
+ it "routes without extra options" do
20
+ self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action"}, { :method=> :get, :path=>"path" })
21
+ get("path").should route_to("controller#action")
22
+ end
23
+
24
+ end
25
+
11
26
  context "with should" do
12
27
  context "when assert_recognizes passes" do
13
28
  it "passes" do
@@ -1,7 +1,10 @@
1
+ ActiveRecord::Base.establish_connection(
2
+ :adapter => 'sqlite3',
3
+ :database => ':memory:'
4
+ )
5
+
1
6
  module Connections
2
7
  def self.extended(host)
3
- host.establish_connection :adapter => 'sqlite3',
4
- :database => ':memory:'
5
8
 
6
9
  host.connection.execute <<-eosql
7
10
  CREATE TABLE #{host.table_name} (
@@ -2,12 +2,6 @@ require "spec_helper"
2
2
 
3
3
  module RSpec::Rails
4
4
  describe ViewRendering do
5
- let(:controller) do
6
- double("controller").tap do |controller|
7
- controller.stub_chain("class.respond_to?").and_return(true)
8
- end
9
- end
10
-
11
5
  let(:group) do
12
6
  RSpec::Core::ExampleGroup.describe do
13
7
  def controller
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)
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers::define :be_included_in_files_in do |path|
2
+ match do |mod|
3
+ stub_metadata(
4
+ :example_group => {:file_path => "#{path}whatever_spec.rb:15"}
5
+ )
6
+ group = RSpec::Core::ExampleGroup.describe
7
+ group.included_modules.include?(mod)
8
+ end
9
+ end
@@ -5,9 +5,17 @@ generate('integration_test widgets')
5
5
  generate('mailer Notifications signup')
6
6
  generate('model thing name:string')
7
7
  generate('helper things')
8
- generate('scaffold widget name:string category:string instock:boolean')
8
+ generate('scaffold widget name:string category:string instock:boolean --force')
9
9
  generate('observer widget')
10
10
  generate('scaffold gadget') # scaffold with no attributes
11
+ generate('scaffold admin/accounts name:string') # scaffold with nested resource
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}
11
19
 
12
20
  run('rake db:migrate')
13
21
  run('rake db:test:prepare')