rspec-rails 2.0.0.beta.12 → 2.0.0.beta.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Gemfile +8 -2
  2. data/README.markdown +39 -0
  3. data/Rakefile +16 -32
  4. data/VERSION +1 -1
  5. data/features/routing_specs/be_routable_matcher.feature +64 -0
  6. data/features/support/env.rb +19 -2
  7. data/lib/autotest/rails_rspec2.rb +4 -1
  8. data/lib/generators/rspec/install/templates/lib/tasks/rspec.rake +1 -1
  9. data/lib/generators/rspec/scaffold/scaffold_generator.rb +1 -1
  10. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
  11. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
  12. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  13. data/lib/rspec/rails.rb +0 -1
  14. data/lib/rspec/rails/adapters.rb +2 -2
  15. data/lib/rspec/rails/example.rb +1 -0
  16. data/lib/rspec/rails/example/controller_example_group.rb +3 -1
  17. data/lib/rspec/rails/example/helper_example_group.rb +3 -2
  18. data/lib/rspec/rails/example/mailer_example_group.rb +1 -0
  19. data/lib/rspec/rails/example/request_example_group.rb +15 -0
  20. data/lib/rspec/rails/example/routing_example_group.rb +25 -0
  21. data/lib/rspec/rails/example/view_example_group.rb +21 -7
  22. data/lib/rspec/rails/matchers.rb +16 -58
  23. data/lib/rspec/rails/matchers/be_a_new.rb +5 -0
  24. data/lib/rspec/rails/matchers/have_extension.rb +23 -0
  25. data/lib/rspec/rails/matchers/redirect_to.rb +15 -0
  26. data/lib/rspec/rails/matchers/render_template.rb +16 -0
  27. data/lib/rspec/rails/matchers/routing_spec_matchers.rb +28 -0
  28. data/lib/rspec/rails/monkey.rb +0 -3
  29. data/lib/rspec/rails/view_rendering.rb +4 -1
  30. data/rspec-rails.gemspec +18 -11
  31. data/spec/rspec/rails/example/helper_example_group_spec.rb +1 -1
  32. data/spec/rspec/rails/example/routing_example_group_spec.rb +13 -0
  33. data/spec/rspec/rails/example/view_example_group_spec.rb +3 -0
  34. data/spec/rspec/rails/matchers/redirect_to_spec.rb +1 -1
  35. data/spec/rspec/rails/matchers/render_template_spec.rb +1 -1
  36. data/spec/rspec/rails/matchers/route_to_spec.rb +53 -0
  37. data/templates/Gemfile +7 -26
  38. data/templates/run_specs.rb +1 -1
  39. metadata +26 -19
  40. data/lib/rspec/rails/monkey/action_controller/test_case.rb +0 -207
  41. data/lib/rspec/rails/monkey/action_view/test_case.rb +0 -203
  42. data/lib/rspec/rails/monkey/active_support/notifications/fanout.rb +0 -20
  43. data/lib/rspec/rails/null_resolver.rb +0 -10
@@ -1,4 +1,4 @@
1
- run('rspec spec -cfdoc')
1
+ run('bundle exec rspec spec -cfdoc')
2
2
  run('rake spec')
3
3
  run('rake spec:requests')
4
4
  run('rake spec:models')
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 12
11
- version: 2.0.0.beta.12
10
+ - 13
11
+ version: 2.0.0.beta.13
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Chelimsky
@@ -17,13 +17,13 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-14 00:00:00 -05:00
20
+ date: 2010-06-23 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
+ type: :runtime
24
25
  name: rspec
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "="
29
29
  - !ruby/object:Gem::Version
@@ -32,14 +32,14 @@ dependencies:
32
32
  - 0
33
33
  - 0
34
34
  - beta
35
- - 12
36
- version: 2.0.0.beta.12
37
- type: :runtime
38
- version_requirements: *id001
35
+ - 13
36
+ version: 2.0.0.beta.13
37
+ requirement: *id001
38
+ prerelease: false
39
39
  - !ruby/object:Gem::Dependency
40
+ type: :runtime
40
41
  name: webrat
41
- prerelease: false
42
- requirement: &id002 !ruby/object:Gem::Requirement
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
@@ -48,8 +48,8 @@ dependencies:
48
48
  - 7
49
49
  - 0
50
50
  version: 0.7.0
51
- type: :runtime
52
- version_requirements: *id002
51
+ requirement: *id002
52
+ prerelease: false
53
53
  description: RSpec-2 for Rails-3
54
54
  email: dchelimsky@gmail.com;chad.humphries@gmail.com
55
55
  executables: []
@@ -74,6 +74,7 @@ files:
74
74
  - features/matchers/new_record_matcher.feature
75
75
  - features/model_specs/errors_on.feature
76
76
  - features/model_specs/transactional_examples.feature
77
+ - features/routing_specs/be_routable_matcher.feature
77
78
  - features/step_definitions/model_steps.rb
78
79
  - features/support/env.rb
79
80
  - features/view_specs/view_spec.feature
@@ -117,18 +118,20 @@ files:
117
118
  - lib/rspec/rails/example/helper_example_group.rb
118
119
  - lib/rspec/rails/example/mailer_example_group.rb
119
120
  - lib/rspec/rails/example/request_example_group.rb
121
+ - lib/rspec/rails/example/routing_example_group.rb
120
122
  - lib/rspec/rails/example/view_example_group.rb
121
123
  - lib/rspec/rails/extensions.rb
122
124
  - lib/rspec/rails/extensions/active_record/base.rb
123
125
  - lib/rspec/rails/fixture_support.rb
124
126
  - lib/rspec/rails/matchers.rb
127
+ - lib/rspec/rails/matchers/be_a_new.rb
128
+ - lib/rspec/rails/matchers/have_extension.rb
129
+ - lib/rspec/rails/matchers/redirect_to.rb
130
+ - lib/rspec/rails/matchers/render_template.rb
131
+ - lib/rspec/rails/matchers/routing_spec_matchers.rb
125
132
  - lib/rspec/rails/mocks.rb
126
133
  - lib/rspec/rails/monkey.rb
127
- - lib/rspec/rails/monkey/action_controller/test_case.rb
128
134
  - lib/rspec/rails/monkey/action_mailer/test_case.rb
129
- - lib/rspec/rails/monkey/action_view/test_case.rb
130
- - lib/rspec/rails/monkey/active_support/notifications/fanout.rb
131
- - lib/rspec/rails/null_resolver.rb
132
135
  - lib/rspec/rails/version.rb
133
136
  - lib/rspec/rails/view_assigns.rb
134
137
  - lib/rspec/rails/view_rendering.rb
@@ -137,12 +140,14 @@ files:
137
140
  - spec/rspec/rails/example/helper_example_group_spec.rb
138
141
  - spec/rspec/rails/example/mailer_example_group_spec.rb
139
142
  - spec/rspec/rails/example/request_example_group_spec.rb
143
+ - spec/rspec/rails/example/routing_example_group_spec.rb
140
144
  - spec/rspec/rails/example/view_example_group_spec.rb
141
145
  - spec/rspec/rails/example/view_rendering_spec.rb
142
146
  - spec/rspec/rails/matchers/be_a_new_spec.rb
143
147
  - spec/rspec/rails/matchers/errors_on_spec.rb
144
148
  - spec/rspec/rails/matchers/redirect_to_spec.rb
145
149
  - spec/rspec/rails/matchers/render_template_spec.rb
150
+ - spec/rspec/rails/matchers/route_to_spec.rb
146
151
  - spec/rspec/rails/mocks/ar_classes.rb
147
152
  - spec/rspec/rails/mocks/mock_model_spec.rb
148
153
  - spec/rspec/rails/mocks/stub_model_spec.rb
@@ -159,7 +164,7 @@ licenses: []
159
164
  post_install_message: |
160
165
  **************************************************
161
166
 
162
- Thank you for installing rspec-rails-2.0.0.beta.12!
167
+ Thank you for installing rspec-rails-2.0.0.beta.13!
163
168
 
164
169
  This version of rspec-rails only works with
165
170
  versions of rails >= 3.0.0.pre.
@@ -197,18 +202,20 @@ rubyforge_project: rspec
197
202
  rubygems_version: 1.3.6
198
203
  signing_key:
199
204
  specification_version: 3
200
- summary: rspec-rails-2.0.0.beta.12
205
+ summary: rspec-rails-2.0.0.beta.13
201
206
  test_files:
202
207
  - spec/rspec/rails/example/controller_example_group_spec.rb
203
208
  - spec/rspec/rails/example/helper_example_group_spec.rb
204
209
  - spec/rspec/rails/example/mailer_example_group_spec.rb
205
210
  - spec/rspec/rails/example/request_example_group_spec.rb
211
+ - spec/rspec/rails/example/routing_example_group_spec.rb
206
212
  - spec/rspec/rails/example/view_example_group_spec.rb
207
213
  - spec/rspec/rails/example/view_rendering_spec.rb
208
214
  - spec/rspec/rails/matchers/be_a_new_spec.rb
209
215
  - spec/rspec/rails/matchers/errors_on_spec.rb
210
216
  - spec/rspec/rails/matchers/redirect_to_spec.rb
211
217
  - spec/rspec/rails/matchers/render_template_spec.rb
218
+ - spec/rspec/rails/matchers/route_to_spec.rb
212
219
  - spec/rspec/rails/mocks/ar_classes.rb
213
220
  - spec/rspec/rails/mocks/mock_model_spec.rb
214
221
  - spec/rspec/rails/mocks/stub_model_spec.rb
@@ -1,207 +0,0 @@
1
- require 'action_controller'
2
- require 'action_controller/test_case'
3
-
4
- module ActionController
5
- # This has been merged to rails HEAD after the 3.0.0.beta.3 release (see
6
- # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4433).
7
- # Once 3.0.0.rc.1 comes out, we can remove it.
8
- module TemplateAssertions
9
- def teardown_subscriptions
10
- # rails-3.0.0.beta.3
11
- ActiveSupport::Notifications.unsubscribe("action_view.render_template")
12
- ActiveSupport::Notifications.unsubscribe("action_view.render_template!")
13
-
14
- # as of 731d4392e478ff5526b595074d9caa999da8bd0c
15
- ActiveSupport::Notifications.unsubscribe("render_template.action_view")
16
- ActiveSupport::Notifications.unsubscribe("!render_template.action_view")
17
- end
18
- end
19
-
20
- # This has been merged to rails HEAD after the 3.0.0.beta.3 release (see
21
- # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4474).
22
- # Once 3.0.0.rc.1 comes out, we can remove it.
23
- unless defined?(ActionController::TestCase::Behavior)
24
- class TestCase < ActiveSupport::TestCase
25
- module Behavior
26
- extend ActiveSupport::Concern
27
- include ActionDispatch::TestProcess
28
-
29
- attr_reader :response, :request
30
-
31
- module ClassMethods
32
-
33
- # Sets the controller class name. Useful if the name can't be inferred from test class.
34
- # Expects +controller_class+ as a constant. Example: <tt>tests WidgetController</tt>.
35
- def tests(controller_class)
36
- self.controller_class = controller_class
37
- end
38
-
39
- def controller_class=(new_class)
40
- prepare_controller_class(new_class) if new_class
41
- write_inheritable_attribute(:controller_class, new_class)
42
- end
43
-
44
- def controller_class
45
- if current_controller_class = read_inheritable_attribute(:controller_class)
46
- current_controller_class
47
- else
48
- self.controller_class = determine_default_controller_class(name)
49
- end
50
- end
51
-
52
- def determine_default_controller_class(name)
53
- name.sub(/Test$/, '').constantize
54
- rescue NameError
55
- nil
56
- end
57
-
58
- def prepare_controller_class(new_class)
59
- new_class.send :include, ActionController::TestCase::RaiseActionExceptions
60
- end
61
-
62
- end
63
-
64
- # Executes a request simulating GET HTTP method and set/volley the response
65
- def get(action, parameters = nil, session = nil, flash = nil)
66
- process(action, parameters, session, flash, "GET")
67
- end
68
-
69
- # Executes a request simulating POST HTTP method and set/volley the response
70
- def post(action, parameters = nil, session = nil, flash = nil)
71
- process(action, parameters, session, flash, "POST")
72
- end
73
-
74
- # Executes a request simulating PUT HTTP method and set/volley the response
75
- def put(action, parameters = nil, session = nil, flash = nil)
76
- process(action, parameters, session, flash, "PUT")
77
- end
78
-
79
- # Executes a request simulating DELETE HTTP method and set/volley the response
80
- def delete(action, parameters = nil, session = nil, flash = nil)
81
- process(action, parameters, session, flash, "DELETE")
82
- end
83
-
84
- # Executes a request simulating HEAD HTTP method and set/volley the response
85
- def head(action, parameters = nil, session = nil, flash = nil)
86
- process(action, parameters, session, flash, "HEAD")
87
- end
88
-
89
- def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
90
- @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
91
- @request.env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
92
- returning __send__(request_method, action, parameters, session, flash) do
93
- @request.env.delete 'HTTP_X_REQUESTED_WITH'
94
- @request.env.delete 'HTTP_ACCEPT'
95
- end
96
- end
97
- alias xhr :xml_http_request
98
-
99
- def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
100
- # Sanity check for required instance variables so we can give an
101
- # understandable error message.
102
- %w(@routes @controller @request @response).each do |iv_name|
103
- if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
104
- raise "#{iv_name} is nil: make sure you set it in your test's setup method."
105
- end
106
- end
107
-
108
- @request.recycle!
109
- @response.recycle!
110
- @controller.response_body = nil
111
- @controller.formats = nil
112
- @controller.params = nil
113
-
114
- @html_document = nil
115
- @request.env['REQUEST_METHOD'] = http_method
116
-
117
- parameters ||= {}
118
- @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters)
119
-
120
- @request.session = ActionController::TestSession.new(session) unless session.nil?
121
- @request.session["flash"] = @request.flash.update(flash || {})
122
- @request.session["flash"].sweep
123
-
124
- @controller.request = @request
125
- @controller.params.merge!(parameters)
126
- build_request_uri(action, parameters)
127
- Base.class_eval { include Testing }
128
- @controller.process_with_new_base_test(@request, @response)
129
- @request.session.delete('flash') if @request.session['flash'].blank?
130
- @response
131
- end
132
-
133
- def setup_controller_request_and_response
134
- @request = TestRequest.new
135
- @response = TestResponse.new
136
-
137
- if klass = self.class.controller_class
138
- @controller ||= klass.new rescue nil
139
- end
140
-
141
- @request.env.delete('PATH_INFO')
142
-
143
- if @controller
144
- @controller.request = @request
145
- @controller.params = {}
146
- end
147
- end
148
-
149
- # Cause the action to be rescued according to the regular rules for rescue_action when the visitor is not local
150
- def rescue_action_in_public!
151
- @request.remote_addr = '208.77.188.166' # example.com
152
- end
153
-
154
- included do
155
- include ActionController::TemplateAssertions
156
- include ActionDispatch::Assertions
157
- setup :setup_controller_request_and_response
158
- end
159
-
160
- private
161
-
162
- def build_request_uri(action, parameters)
163
- unless @request.env["PATH_INFO"]
164
- options = @controller.__send__(:url_options).merge(parameters)
165
- options.update(
166
- :only_path => true,
167
- :action => action,
168
- :relative_url_root => nil,
169
- :_path_segments => @request.symbolized_path_parameters)
170
-
171
- url, query_string = @routes.url_for(options).split("?", 2)
172
-
173
- @request.env["SCRIPT_NAME"] = @controller.config.relative_url_root
174
- @request.env["PATH_INFO"] = url
175
- @request.env["QUERY_STRING"] = query_string || ""
176
- end
177
- end
178
- end
179
-
180
- # When the request.remote_addr remains the default for testing, which is 0.0.0.0, the exception is simply raised inline
181
- # (bystepping the regular exception handling from rescue_action). If the request.remote_addr is anything else, the regular
182
- # rescue_action process takes place. This means you can test your rescue_action code by setting remote_addr to something else
183
- # than 0.0.0.0.
184
- #
185
- # The exception is stored in the exception accessor for further inspection.
186
- module RaiseActionExceptions
187
- def self.included(base)
188
- base.class_eval do
189
- attr_accessor :exception
190
- protected :exception, :exception=
191
- end
192
- end
193
-
194
- protected
195
- def rescue_action_without_handler(e)
196
- self.exception = e
197
-
198
- if request.remote_addr == "0.0.0.0"
199
- raise(e)
200
- else
201
- super(e)
202
- end
203
- end
204
- end
205
- end
206
- end
207
- end
@@ -1,203 +0,0 @@
1
- require 'active_support/core_ext/object/blank'
2
- require 'action_controller'
3
- require 'action_controller/test_case'
4
- require 'action_view'
5
-
6
- unless defined?(ActionView::TestCase::Behavior)
7
-
8
-
9
- # This has been merged to rails HEAD after the 3.0.0.beta.3 release (see
10
- # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4678).
11
- # Once 3.0.0.rc.1 comes out, we can remove it.
12
- module ActionView
13
-
14
- # This line is NOT part of the code merged into Rails, but ensures that
15
- # we're using the correct code for rails-3.0.0.beta.3
16
- remove_const :TestCase
17
-
18
- class TestCase < ActiveSupport::TestCase
19
- class TestController < ActionController::Base
20
- include ActionDispatch::TestProcess
21
-
22
- attr_accessor :request, :response, :params
23
-
24
- class << self
25
- attr_writer :controller_path
26
- end
27
-
28
- def controller_path=(path)
29
- self.class.controller_path=(path)
30
- end
31
-
32
- def initialize
33
- self.class.controller_path = ""
34
- @request = ActionController::TestRequest.new
35
- @response = ActionController::TestResponse.new
36
-
37
- @request.env.delete('PATH_INFO')
38
-
39
- @params = {}
40
- end
41
- end
42
-
43
- module Behavior
44
- extend ActiveSupport::Concern
45
-
46
- include ActionDispatch::Assertions, ActionDispatch::TestProcess
47
- include ActionController::TemplateAssertions
48
- include ActionView::Context
49
-
50
- include ActionController::PolymorphicRoutes
51
- include ActionController::RecordIdentifier
52
-
53
- include AbstractController::Helpers
54
- include ActionView::Helpers
55
-
56
- attr_accessor :controller, :output_buffer, :rendered
57
-
58
- module ClassMethods
59
- def tests(helper_class)
60
- self.helper_class = helper_class
61
- end
62
-
63
- def determine_default_helper_class(name)
64
- mod = name.sub(/Test$/, '').constantize
65
- mod.is_a?(Class) ? nil : mod
66
- rescue NameError
67
- nil
68
- end
69
-
70
- def helper_method(*methods)
71
- # Almost a duplicate from ActionController::Helpers
72
- methods.flatten.each do |method|
73
- _helpers.module_eval <<-end_eval
74
- def #{method}(*args, &block) # def current_user(*args, &block)
75
- _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block)
76
- end # end
77
- end_eval
78
- end
79
- end
80
-
81
- attr_writer :helper_class
82
-
83
- def helper_class
84
- @helper_class ||= determine_default_helper_class(name)
85
- end
86
-
87
- private
88
-
89
- def include_helper_modules!
90
- helper(helper_class) if helper_class
91
- include _helpers
92
- end
93
-
94
- end
95
-
96
- def setup_with_controller
97
- @controller = ActionView::TestCase::TestController.new
98
- @output_buffer = ActiveSupport::SafeBuffer.new
99
- @rendered = ''
100
-
101
- self.class.send(:include_helper_modules!)
102
- make_test_case_available_to_view!
103
- say_no_to_protect_against_forgery!
104
- end
105
-
106
- def config
107
- @controller.config if @controller.respond_to?(:config)
108
- end
109
-
110
- def render(options = {}, local_assigns = {}, &block)
111
- @rendered << output = _view.render(options, local_assigns, &block)
112
- output
113
- end
114
-
115
- included do
116
- setup :setup_with_controller
117
- end
118
-
119
- private
120
-
121
- # Support the selector assertions
122
- #
123
- # Need to experiment if this priority is the best one: rendered => output_buffer
124
- def response_from_page_or_rjs
125
- HTML::Document.new(@rendered.blank? ? @output_buffer : @rendered).root
126
- end
127
-
128
- def say_no_to_protect_against_forgery!
129
- _helpers.module_eval do
130
- def protect_against_forgery?
131
- false
132
- end
133
- end
134
- end
135
-
136
- def make_test_case_available_to_view!
137
- test_case_instance = self
138
- _helpers.module_eval do
139
- define_method(:_test_case) { test_case_instance }
140
- private :_test_case
141
- end
142
- end
143
-
144
- def _view
145
- @_view ||= begin
146
- view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
147
- view.singleton_class.send :include, _helpers
148
- view.singleton_class.send :include, @controller._router.url_helpers
149
- view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
150
- view.output_buffer = self.output_buffer
151
- view
152
- end
153
- end
154
-
155
- EXCLUDE_IVARS = %w{
156
- @_result
157
- @output_buffer
158
- @rendered
159
- @templates
160
- @view_context_class
161
- @layouts
162
- @partials
163
- @controller
164
-
165
- @method_name
166
- @fixture_cache
167
- @loaded_fixtures
168
- @test_passed
169
- }
170
-
171
- def _instance_variables
172
- instance_variables - EXCLUDE_IVARS
173
- instance_variables
174
- end
175
-
176
- def _assigns
177
- _instance_variables.inject({}) do |hash, var|
178
- name = var[1..-1].to_sym
179
- hash[name] = instance_variable_get(var)
180
- hash
181
- end
182
- end
183
-
184
- def _router
185
- @controller._router if @controller.respond_to?(:_router)
186
- end
187
-
188
- def method_missing(selector, *args)
189
- if @controller.respond_to?(:_router) &&
190
- @controller._router.named_routes.helpers.include?(selector)
191
- @controller.__send__(selector, *args)
192
- else
193
- super
194
- end
195
- end
196
-
197
- end
198
-
199
- include Behavior
200
-
201
- end
202
- end
203
- end