dchelimsky-rspec-rails 1.1.12 → 1.1.99.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +29 -2
- data/License.txt +1 -1
- data/Manifest.txt +7 -6
- data/README.txt +5 -4
- data/Rakefile +14 -2
- data/TODO.txt +1 -0
- data/Upgrade.txt +30 -0
- data/generators/rspec/templates/rspec.rake +12 -10
- data/generators/rspec/templates/script/spec_server +10 -111
- data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +9 -13
- data/generators/rspec_scaffold/templates/controller_spec.rb +25 -25
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +1 -1
- data/lib/spec/rails/example/controller_example_group.rb +46 -16
- data/lib/spec/rails/example/functional_example_group.rb +7 -22
- data/lib/spec/rails/example/helper_example_group.rb +6 -9
- data/lib/spec/rails/example/model_example_group.rb +1 -1
- data/lib/spec/rails/example/render_observer.rb +0 -26
- data/lib/spec/rails/example/view_example_group.rb +32 -34
- data/lib/spec/rails/example.rb +0 -2
- data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
- data/lib/spec/rails/extensions.rb +1 -1
- data/lib/spec/rails/matchers/ar_be_valid.rb +3 -0
- data/lib/spec/rails/matchers/have_text.rb +1 -1
- data/lib/spec/rails/matchers/include_text.rb +2 -2
- data/lib/spec/rails/matchers/redirect_to.rb +6 -14
- data/lib/spec/rails/matchers/render_template.rb +5 -1
- data/lib/spec/rails/spec_server.rb +86 -0
- data/lib/spec/rails/version.rb +2 -2
- data/lib/spec/rails.rb +10 -9
- data/rspec-rails.gemspec +12 -9
- data/spec/resources/controllers/controller_spec_controller.rb +1 -1
- data/spec/resources/controllers/render_spec_controller.rb +1 -1
- data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
- data/spec/spec/rails/example/configuration_spec.rb +15 -29
- data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +84 -60
- data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
- data/spec/spec/rails/example/example_group_factory_spec.rb +5 -5
- data/spec/spec/rails/example/{helper_spec_spec.rb → helper_example_group_spec.rb} +8 -2
- data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
- data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +33 -15
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
- data/spec/spec/rails/matchers/assert_select_spec.rb +1 -0
- data/spec/spec/rails/matchers/have_text_spec.rb +12 -4
- data/spec/spec/rails/matchers/include_text_spec.rb +11 -13
- data/spec/spec/rails/matchers/redirect_to_spec.rb +221 -210
- data/spec/spec/rails/matchers/render_template_spec.rb +161 -158
- data/spec/spec/rails/spec_server_spec.rb +18 -7
- data/spec/spec_helper.rb +20 -9
- metadata +21 -10
- data/lib/spec/rails/example/rails_example_group.rb +0 -28
- data/lib/spec/rails/extensions/action_controller/base.rb +0 -14
@@ -2,57 +2,61 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
|
|
2
2
|
|
3
3
|
describe <%= controller_class_name %>Controller do
|
4
4
|
describe "route generation" do
|
5
|
-
it "
|
5
|
+
it "maps #index" do
|
6
6
|
route_for(:controller => "<%= table_name %>", :action => "index").should == "/<%= table_name %>"
|
7
7
|
end
|
8
8
|
|
9
|
-
it "
|
9
|
+
it "maps #new" do
|
10
10
|
route_for(:controller => "<%= table_name %>", :action => "new").should == "/<%= table_name %>/new"
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
14
|
-
route_for(:controller => "<%= table_name %>", :action => "show", :id => 1).should == "/<%= table_name %>/1"
|
13
|
+
it "maps #show" do
|
14
|
+
route_for(:controller => "<%= table_name %>", :action => "show", :id => "1").should == "/<%= table_name %>/1"
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
18
|
-
route_for(:controller => "<%= table_name %>", :action => "edit", :id => 1).should == "/<%= table_name %>/1
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should map #update" do
|
22
|
-
route_for(:controller => "<%= table_name %>", :action => "update", :id => 1).should == "/<%= table_name %>/1"
|
17
|
+
it "maps #edit" do
|
18
|
+
route_for(:controller => "<%= table_name %>", :action => "edit", :id => "1").should == "/<%= table_name %>/1/edit"
|
23
19
|
end
|
20
|
+
|
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 "
|
26
|
-
route_for(:controller => "<%= table_name %>", :action => "destroy", :id => 1).should == "/<%= table_name %>/1"
|
29
|
+
it "maps #destroy" do
|
30
|
+
route_for(:controller => "<%= table_name %>", :action => "destroy", :id => "1").should == {:path =>"/<%= table_name %>/1", :method => :delete}
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
34
|
describe "route recognition" do
|
31
|
-
it "
|
35
|
+
it "generates params for #index" do
|
32
36
|
params_from(:get, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "index"}
|
33
37
|
end
|
34
38
|
|
35
|
-
it "
|
39
|
+
it "generates params for #new" do
|
36
40
|
params_from(:get, "/<%= table_name %>/new").should == {:controller => "<%= table_name %>", :action => "new"}
|
37
41
|
end
|
38
42
|
|
39
|
-
it "
|
43
|
+
it "generates params for #create" do
|
40
44
|
params_from(:post, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "create"}
|
41
45
|
end
|
42
46
|
|
43
|
-
it "
|
47
|
+
it "generates params for #show" do
|
44
48
|
params_from(:get, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "show", :id => "1"}
|
45
49
|
end
|
46
50
|
|
47
|
-
it "
|
48
|
-
params_from(:get, "/<%= table_name %>/1
|
51
|
+
it "generates params for #edit" do
|
52
|
+
params_from(:get, "/<%= table_name %>/1/edit").should == {:controller => "<%= table_name %>", :action => "edit", :id => "1"}
|
49
53
|
end
|
50
54
|
|
51
|
-
it "
|
55
|
+
it "generates params for #update" do
|
52
56
|
params_from(:put, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "update", :id => "1"}
|
53
57
|
end
|
54
58
|
|
55
|
-
it "
|
59
|
+
it "generates params for #destroy" do
|
56
60
|
params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
|
57
61
|
end
|
58
62
|
end
|
@@ -13,7 +13,7 @@ describe "/<%= table_name %>/show.<%= default_file_extension %>" do
|
|
13
13
|
<% end -%>
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "renders attributes in <p>" do
|
17
17
|
render "/<%= table_name %>/show.<%= default_file_extension %>"
|
18
18
|
<% for attribute in output_attributes -%>
|
19
19
|
response.should have_text(/<%= Regexp.escape(attribute.default_value).gsub(/^"|"$/, '')%>/)
|
@@ -61,10 +61,17 @@ module Spec
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def inherited(klass) # :nodoc:
|
64
|
-
klass.controller_class_name = controller_class_name
|
65
64
|
klass.integrate_views(integrate_views?)
|
65
|
+
klass.subject { controller }
|
66
66
|
super
|
67
67
|
end
|
68
|
+
|
69
|
+
def set_description(*args)
|
70
|
+
super
|
71
|
+
if described_class && described_class.ancestors.include?(ActionController::Base)
|
72
|
+
tests described_class
|
73
|
+
end
|
74
|
+
end
|
68
75
|
|
69
76
|
# You MUST provide a controller_name within the context of
|
70
77
|
# your controller specs:
|
@@ -73,11 +80,10 @@ module Spec
|
|
73
80
|
# controller_name :thing
|
74
81
|
# ...
|
75
82
|
def controller_name(name)
|
76
|
-
|
83
|
+
tests "#{name}_controller".camelize.constantize
|
77
84
|
end
|
78
|
-
attr_accessor :controller_class_name # :nodoc:
|
79
85
|
end
|
80
|
-
|
86
|
+
|
81
87
|
before(:each) do
|
82
88
|
# Some Rails apps explicitly disable ActionMailer in environment.rb
|
83
89
|
if defined?(ActionMailer)
|
@@ -107,14 +113,26 @@ module Spec
|
|
107
113
|
|
108
114
|
def initialize(defined_description, options={}, &implementation) #:nodoc:
|
109
115
|
super
|
110
|
-
controller_class_name = self.class.controller_class_name
|
111
|
-
if controller_class_name
|
112
|
-
@controller_class_name = controller_class_name.to_s
|
113
|
-
else
|
114
|
-
@controller_class_name = self.class.described_type.to_s
|
115
|
-
end
|
116
116
|
@integrate_views = self.class.integrate_views?
|
117
117
|
end
|
118
|
+
|
119
|
+
class RouteForMatcher
|
120
|
+
def initialize(example, options)
|
121
|
+
@example, @options = example, options
|
122
|
+
end
|
123
|
+
|
124
|
+
def ==(expected)
|
125
|
+
if Hash === expected
|
126
|
+
path, querystring = expected[:path].split('?')
|
127
|
+
path = expected.merge(:path => path)
|
128
|
+
else
|
129
|
+
path, querystring = expected.split('?')
|
130
|
+
end
|
131
|
+
params = querystring.blank? ? {} : @example.params_from_querystring(querystring)
|
132
|
+
@example.assert_recognizes(@options, path, params)
|
133
|
+
true
|
134
|
+
end
|
135
|
+
end
|
118
136
|
|
119
137
|
# Uses ActionController::Routing::Routes to generate
|
120
138
|
# the correct route for a given set of options.
|
@@ -122,28 +140,40 @@ module Spec
|
|
122
140
|
# route_for(:controller => 'registrations', :action => 'edit', :id => 1)
|
123
141
|
# => '/registrations/1;edit'
|
124
142
|
def route_for(options)
|
125
|
-
|
126
|
-
ActionController::Routing::Routes.generate(options)
|
143
|
+
RouteForMatcher.new(self, options)
|
127
144
|
end
|
128
145
|
|
129
146
|
# Uses ActionController::Routing::Routes to parse
|
130
147
|
# an incoming path so the parameters it generates can be checked
|
131
148
|
# == Example
|
132
|
-
# params_from(:get, '/registrations/1
|
149
|
+
# params_from(:get, '/registrations/1/edit')
|
133
150
|
# => :controller => 'registrations', :action => 'edit', :id => 1
|
134
151
|
def params_from(method, path)
|
135
152
|
ensure_that_routes_are_loaded
|
136
|
-
|
153
|
+
path, querystring = path.split('?')
|
154
|
+
params = ActionController::Routing::Routes.recognize_path(path, :method => method)
|
155
|
+
querystring.blank? ? params : params.merge(params_from_querystring(querystring))
|
137
156
|
end
|
138
157
|
|
139
|
-
|
158
|
+
def params_from_querystring(querystring) # :nodoc:
|
159
|
+
params = {}
|
160
|
+
querystring.split('&').each do |piece|
|
161
|
+
key, value = piece.split('=')
|
162
|
+
params[key.to_sym] = value
|
163
|
+
end
|
164
|
+
params
|
165
|
+
end
|
166
|
+
|
167
|
+
protected
|
168
|
+
|
140
169
|
def _assigns_hash_proxy
|
141
170
|
@_assigns_hash_proxy ||= AssignsHashProxy.new self do
|
142
171
|
@response.template
|
143
172
|
end
|
144
173
|
end
|
145
174
|
|
146
|
-
|
175
|
+
private
|
176
|
+
|
147
177
|
def ensure_that_routes_are_loaded
|
148
178
|
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
|
149
179
|
end
|
@@ -1,21 +1,15 @@
|
|
1
|
+
require 'action_controller/test_case'
|
2
|
+
|
1
3
|
module Spec
|
2
4
|
module Rails
|
3
5
|
module Example
|
4
|
-
class FunctionalExampleGroup <
|
5
|
-
|
6
|
-
|
6
|
+
class FunctionalExampleGroup < ActionController::TestCase
|
7
|
+
def setup
|
8
|
+
# no-op to override AC::TC's setup w/ conflicts with the before(:each) below
|
9
|
+
end
|
7
10
|
|
8
11
|
attr_reader :request, :response
|
9
|
-
before(:each) do
|
10
|
-
@controller_class = @controller_class_name.split('::').inject(Object) { |k,n| k.const_get n }
|
11
|
-
raise "Can't determine controller class for #{@controller_class_name}" if @controller_class.nil?
|
12
12
|
|
13
|
-
@controller = @controller_class.new
|
14
|
-
@request = ActionController::TestRequest.new
|
15
|
-
@response = ActionController::TestResponse.new
|
16
|
-
@response.session = @request.session
|
17
|
-
end
|
18
|
-
|
19
13
|
def params
|
20
14
|
request.parameters
|
21
15
|
end
|
@@ -25,7 +19,7 @@ module Spec
|
|
25
19
|
end
|
26
20
|
|
27
21
|
def session
|
28
|
-
|
22
|
+
request.session
|
29
23
|
end
|
30
24
|
|
31
25
|
# Overrides the <tt>cookies()</tt> method in
|
@@ -35,15 +29,6 @@ module Spec
|
|
35
29
|
# cookies in examples using the same API with which you set and read
|
36
30
|
# them in controllers.
|
37
31
|
#
|
38
|
-
# == Examples (Rails >= 1.2.6)
|
39
|
-
#
|
40
|
-
# cookies[:user_id] = '1234'
|
41
|
-
# get :index
|
42
|
-
# assigns[:user].id.should == '1234'
|
43
|
-
#
|
44
|
-
# post :login
|
45
|
-
# cookies[:login].expires.should == 1.week.from_now
|
46
|
-
#
|
47
32
|
# == Examples (Rails 2.0 > 2.2)
|
48
33
|
#
|
49
34
|
# cookies[:user_id] = {:value => '1234', :expires => 1.minute.ago}
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Spec
|
2
2
|
module Rails
|
3
3
|
module Example
|
4
|
+
class HelperExampleGroupController < ApplicationController #:nodoc:
|
5
|
+
attr_accessor :request, :url
|
6
|
+
end
|
7
|
+
|
4
8
|
# Helper Specs live in $RAILS_ROOT/spec/helpers/.
|
5
9
|
#
|
6
10
|
# Helper Specs use Spec::Rails::Example::HelperExampleGroup, which allows you to
|
@@ -12,7 +16,7 @@ module Spec
|
|
12
16
|
#
|
13
17
|
# == Example
|
14
18
|
#
|
15
|
-
#
|
19
|
+
# module ThingHelper
|
16
20
|
# def number_of_things
|
17
21
|
# Thing.count
|
18
22
|
# end
|
@@ -26,6 +30,7 @@ module Spec
|
|
26
30
|
# end
|
27
31
|
# end
|
28
32
|
class HelperExampleGroup < FunctionalExampleGroup
|
33
|
+
tests HelperExampleGroupController
|
29
34
|
attr_accessor :output_buffer
|
30
35
|
|
31
36
|
class HelperObject < ActionView::Base
|
@@ -109,10 +114,6 @@ module Spec
|
|
109
114
|
include mod if mod.parents.include?(ActionView::Helpers)
|
110
115
|
end
|
111
116
|
|
112
|
-
before(:all) do
|
113
|
-
@controller_class_name = 'Spec::Rails::Example::HelperExampleGroupController'
|
114
|
-
end
|
115
|
-
|
116
117
|
before(:each) do
|
117
118
|
@controller.request = @request
|
118
119
|
@controller.url = ActionController::UrlRewriter.new @request, {} # url_for
|
@@ -162,10 +163,6 @@ module Spec
|
|
162
163
|
end
|
163
164
|
|
164
165
|
end
|
165
|
-
|
166
|
-
class HelperExampleGroupController < ApplicationController #:nodoc:
|
167
|
-
attr_accessor :request, :url
|
168
|
-
end
|
169
166
|
end
|
170
167
|
end
|
171
168
|
end
|
@@ -6,7 +6,7 @@ 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 <
|
9
|
+
class ModelExampleGroup < ActiveSupport::TestCase
|
10
10
|
Spec::Example::ExampleGroupFactory.register(:model, self)
|
11
11
|
end
|
12
12
|
end
|
@@ -8,32 +8,6 @@ module Spec
|
|
8
8
|
# and template and view examples
|
9
9
|
module RenderObserver
|
10
10
|
|
11
|
-
# DEPRECATED
|
12
|
-
#
|
13
|
-
# Use should_receive(:render).with(opts) instead
|
14
|
-
def expect_render(opts={})
|
15
|
-
warn_deprecation("expect_render", "should_receive")
|
16
|
-
register_verify_after_each
|
17
|
-
render_proxy.should_receive(:render, :expected_from => caller(1)[0]).with(opts)
|
18
|
-
end
|
19
|
-
|
20
|
-
# DEPRECATED
|
21
|
-
#
|
22
|
-
# Use stub!(:render).with(opts) instead
|
23
|
-
def stub_render(opts={})
|
24
|
-
warn_deprecation("stub_render", "stub!")
|
25
|
-
register_verify_after_each
|
26
|
-
render_proxy.stub!(:render, :expected_from => caller(1)[0]).with(opts)
|
27
|
-
end
|
28
|
-
|
29
|
-
def warn_deprecation(deprecated_method, new_method)
|
30
|
-
Kernel.warn <<-WARNING
|
31
|
-
#{deprecated_method} is deprecated and will be removed from a future version of rspec-rails.
|
32
|
-
|
33
|
-
Please just use object.#{new_method} instead.
|
34
|
-
WARNING
|
35
|
-
end
|
36
|
-
|
37
11
|
def verify_rendered # :nodoc:
|
38
12
|
render_proxy.rspec_verify
|
39
13
|
end
|
@@ -1,6 +1,29 @@
|
|
1
1
|
module Spec
|
2
2
|
module Rails
|
3
3
|
module Example
|
4
|
+
class ViewExampleGroupController < ApplicationController #:nodoc:
|
5
|
+
include Spec::Rails::Example::RenderObserver
|
6
|
+
attr_reader :template
|
7
|
+
|
8
|
+
def add_helper_for(template_path)
|
9
|
+
add_helper(template_path.split('/')[0])
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_helper(name)
|
13
|
+
begin
|
14
|
+
helper_module = "#{name}_helper".camelize.constantize
|
15
|
+
rescue
|
16
|
+
return
|
17
|
+
end
|
18
|
+
(class << template; self; end).class_eval do
|
19
|
+
include helper_module
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def forget_variables_added_to_assigns
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
4
27
|
# View Examples live in $RAILS_ROOT/spec/views/.
|
5
28
|
#
|
6
29
|
# View Specs use Spec::Rails::Example::ViewExampleGroup,
|
@@ -24,22 +47,21 @@ module Spec
|
|
24
47
|
# end
|
25
48
|
# end
|
26
49
|
class ViewExampleGroup < FunctionalExampleGroup
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
50
|
+
tests ViewExampleGroupController
|
51
|
+
class << self
|
52
|
+
def inherited(klass) # :nodoc:
|
53
|
+
klass.subject { template }
|
54
|
+
super
|
55
|
+
end
|
33
56
|
end
|
34
57
|
|
35
|
-
|
36
|
-
|
37
|
-
@controller_class_name = "Spec::Rails::Example::ViewExampleGroupController"
|
38
|
-
end
|
58
|
+
before {ensure_that_flash_and_session_work_properly}
|
59
|
+
after {ensure_that_base_view_path_is_not_set_across_example_groups}
|
39
60
|
|
40
61
|
def ensure_that_flash_and_session_work_properly #:nodoc:
|
41
62
|
@controller.send :initialize_template_class, @response
|
42
63
|
@controller.send :assign_shortcuts, @request, @response
|
64
|
+
@controller.send :initialize_current_url
|
43
65
|
@session = @controller.session
|
44
66
|
@controller.class.send :public, :flash
|
45
67
|
end
|
@@ -114,8 +136,6 @@ module Spec
|
|
114
136
|
|
115
137
|
@controller.send(:params).reverse_merge! @request.parameters
|
116
138
|
|
117
|
-
@controller.send :initialize_current_url
|
118
|
-
|
119
139
|
@controller.class.instance_eval %{
|
120
140
|
def controller_path
|
121
141
|
"#{derived_controller_name(options)}"
|
@@ -156,28 +176,6 @@ module Spec
|
|
156
176
|
end
|
157
177
|
end
|
158
178
|
|
159
|
-
class ViewExampleGroupController < ApplicationController #:nodoc:
|
160
|
-
include Spec::Rails::Example::RenderObserver
|
161
|
-
attr_reader :template
|
162
|
-
|
163
|
-
def add_helper_for(template_path)
|
164
|
-
add_helper(template_path.split('/')[0])
|
165
|
-
end
|
166
|
-
|
167
|
-
def add_helper(name)
|
168
|
-
begin
|
169
|
-
helper_module = "#{name}_helper".camelize.constantize
|
170
|
-
rescue
|
171
|
-
return
|
172
|
-
end
|
173
|
-
(class << template; self; end).class_eval do
|
174
|
-
include helper_module
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def forget_variables_added_to_assigns
|
179
|
-
end
|
180
|
-
end
|
181
179
|
end
|
182
180
|
end
|
183
181
|
end
|
data/lib/spec/rails/example.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
dir = File.dirname(__FILE__)
|
2
2
|
|
3
3
|
require 'spec/rails/example/assigns_hash_proxy'
|
4
|
-
|
5
4
|
require "spec/rails/example/render_observer"
|
6
|
-
require "spec/rails/example/rails_example_group"
|
7
5
|
require "spec/rails/example/model_example_group"
|
8
6
|
require "spec/rails/example/functional_example_group"
|
9
7
|
require "spec/rails/example/controller_example_group"
|
@@ -1,76 +1,44 @@
|
|
1
1
|
require 'spec/runner/configuration'
|
2
2
|
require 'test_help'
|
3
3
|
|
4
|
-
|
5
|
-
module Spec
|
6
|
-
|
7
|
-
|
4
|
+
if defined?(ActiveRecord::Base)
|
5
|
+
module Spec
|
6
|
+
module Runner
|
7
|
+
class Configuration
|
8
8
|
|
9
|
-
TEST_CASE = ActiveSupport.const_defined?(:TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase
|
10
|
-
|
11
|
-
# Rails 1.2.3 does a copy of the @inheritable_attributes to the subclass when the subclass is
|
12
|
-
# created. This causes an ordering issue when setting state on Configuration because the data is
|
13
|
-
# already copied.
|
14
|
-
# Iterating over EXAMPLE_GROUP_CLASSES causes the base ExampleGroup classes to have their
|
15
|
-
# @inheritable_attributes updated.
|
16
|
-
# TODO: BT - When we no longer support Rails 1.2.3, we can remove this functionality
|
17
|
-
EXAMPLE_GROUP_CLASSES = [
|
18
|
-
TEST_CASE,
|
19
|
-
::Spec::Rails::Example::RailsExampleGroup,
|
20
|
-
::Spec::Rails::Example::FunctionalExampleGroup,
|
21
|
-
::Spec::Rails::Example::ControllerExampleGroup,
|
22
|
-
::Spec::Rails::Example::ViewExampleGroup,
|
23
|
-
::Spec::Rails::Example::HelperExampleGroup,
|
24
|
-
::Spec::Rails::Example::ModelExampleGroup
|
25
|
-
]
|
26
|
-
# All of this is ActiveRecord related and makes no sense if it's not used by the app
|
27
|
-
if defined?(ActiveRecord::Base)
|
28
9
|
def initialize
|
29
10
|
super
|
30
11
|
self.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
31
12
|
end
|
32
13
|
|
33
14
|
def use_transactional_fixtures
|
34
|
-
|
15
|
+
ActiveSupport::TestCase.use_transactional_fixtures
|
35
16
|
end
|
36
17
|
def use_transactional_fixtures=(value)
|
37
|
-
|
38
|
-
example_group.use_transactional_fixtures = value
|
39
|
-
end
|
18
|
+
ActiveSupport::TestCase.use_transactional_fixtures = value
|
40
19
|
end
|
41
20
|
|
42
21
|
def use_instantiated_fixtures
|
43
|
-
|
22
|
+
ActiveSupport::TestCase.use_instantiated_fixtures
|
44
23
|
end
|
45
24
|
def use_instantiated_fixtures=(value)
|
46
|
-
|
47
|
-
example_group.use_instantiated_fixtures = value
|
48
|
-
end
|
25
|
+
ActiveSupport::TestCase.use_instantiated_fixtures = value
|
49
26
|
end
|
50
27
|
|
51
28
|
def fixture_path
|
52
|
-
|
29
|
+
ActiveSupport::TestCase.fixture_path
|
53
30
|
end
|
54
31
|
def fixture_path=(path)
|
55
|
-
|
56
|
-
example_group.fixture_path = path
|
57
|
-
end
|
32
|
+
ActiveSupport::TestCase.fixture_path = path
|
58
33
|
end
|
59
34
|
|
60
35
|
def global_fixtures
|
61
|
-
|
36
|
+
ActiveSupport::TestCase.fixture_table_names
|
62
37
|
end
|
63
38
|
def global_fixtures=(fixtures)
|
64
|
-
|
65
|
-
example_group.fixtures(*fixtures)
|
66
|
-
end
|
39
|
+
ActiveSupport::TestCase.fixtures(*fixtures)
|
67
40
|
end
|
68
41
|
end
|
69
42
|
end
|
70
43
|
end
|
71
44
|
end
|
72
|
-
rescue Exception => e
|
73
|
-
puts e.message
|
74
|
-
puts e.backtrace
|
75
|
-
raise e
|
76
|
-
end
|
@@ -3,8 +3,8 @@ require 'spec'
|
|
3
3
|
require 'spec/rails/extensions/spec/runner/configuration'
|
4
4
|
require 'spec/rails/extensions/spec/matchers/have'
|
5
5
|
|
6
|
+
require 'spec/rails/extensions/active_support/test_case'
|
6
7
|
require 'spec/rails/extensions/active_record/base'
|
7
|
-
require 'spec/rails/extensions/action_controller/base'
|
8
8
|
require 'spec/rails/extensions/action_controller/rescue'
|
9
9
|
require 'spec/rails/extensions/action_controller/test_response'
|
10
10
|
require 'spec/rails/extensions/action_view/base'
|
@@ -11,7 +11,11 @@ module Spec
|
|
11
11
|
@request = request
|
12
12
|
end
|
13
13
|
|
14
|
-
def matches?(
|
14
|
+
def matches?(response_or_controller)
|
15
|
+
response = response_or_controller.respond_to?(:response) ?
|
16
|
+
response_or_controller.response :
|
17
|
+
response_or_controller
|
18
|
+
|
15
19
|
@redirected = response.redirect?
|
16
20
|
@actual = response.redirect_url
|
17
21
|
return false unless @redirected
|
@@ -55,7 +59,7 @@ module Spec
|
|
55
59
|
|
56
60
|
def query_hash(url)
|
57
61
|
query = url.split("?", 2)[1] || ""
|
58
|
-
|
62
|
+
Rack::Utils.parse_query(query)
|
59
63
|
end
|
60
64
|
|
61
65
|
def with(options)
|
@@ -95,18 +99,6 @@ module Spec
|
|
95
99
|
def description
|
96
100
|
"redirect to #{@expected.inspect}"
|
97
101
|
end
|
98
|
-
|
99
|
-
class QueryParameterParser
|
100
|
-
def self.parse_query_parameters(query, request)
|
101
|
-
if defined?(CGIMethods)
|
102
|
-
CGIMethods.parse_query_parameters(query)
|
103
|
-
elsif defined?(ActionController::RequestParser)
|
104
|
-
ActionController::RequestParser.parse_query_parameters(query)
|
105
|
-
else
|
106
|
-
request.class.parse_query_parameters(query)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
102
|
end
|
111
103
|
|
112
104
|
# :call-seq:
|
@@ -9,7 +9,11 @@ module Spec
|
|
9
9
|
@expected = expected
|
10
10
|
end
|
11
11
|
|
12
|
-
def matches?(
|
12
|
+
def matches?(response_or_controller)
|
13
|
+
response = response_or_controller.respond_to?(:response) ?
|
14
|
+
response_or_controller.response :
|
15
|
+
response_or_controller
|
16
|
+
|
13
17
|
if response.respond_to?(:rendered_file)
|
14
18
|
@actual = response.rendered_file
|
15
19
|
elsif response.respond_to?(:rendered)
|