rspec-rails 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -1,3 +1,15 @@
1
+ === Version 1.2.5 / 2009-04-29
2
+
3
+ * enhancements
4
+ * support :xml and :strict config options for have_tag matcher (patch from
5
+ Peer Allan and Max Murphy). Closes #783.
6
+
7
+ * bug fixes
8
+ * Fixed a small typo that makes rake stats fail (José Valim). Closes #802.
9
+ * link_to and friends are available to ViewExampleGroup again
10
+ (J.B. Rainsberger). Closes #787.
11
+ * spec_server works correctly with rails 2.3 again (Neil Buckley). Closes #759.
12
+
1
13
  === Version 1.2.4 / 2009-03-13
2
14
 
3
15
  No changes in this release, but aligns with the rspec-1.2.4 release. Someday
@@ -8,7 +8,6 @@ TODO.txt
8
8
  Upgrade.rdoc
9
9
  features/step_definitions/people.rb
10
10
  features/support/env.rb
11
- features/transactions/transactions_should_rollback.feature
12
11
  generators/rspec/CHANGES
13
12
  generators/rspec/rspec_generator.rb
14
13
  generators/rspec/templates/previous_failures.txt
@@ -71,7 +70,6 @@ lib/spec/rails/matchers/redirect_to.rb
71
70
  lib/spec/rails/matchers/render_template.rb
72
71
  lib/spec/rails/mocks.rb
73
72
  lib/spec/rails/spec_server.rb
74
- lib/spec/rails/story_adapter.rb
75
73
  lib/spec/rails/version.rb
76
74
  spec/autotest/mappings_spec.rb
77
75
  spec/rails_suite.rb
@@ -132,6 +130,7 @@ spec/resources/views/view_spec/should_not_receive.html.erb
132
130
  spec/resources/views/view_spec/template_with_partial.html.erb
133
131
  spec/resources/views/view_spec/template_with_partial_using_collection.html.erb
134
132
  spec/resources/views/view_spec/template_with_partial_with_array.html.erb
133
+ spec/resources/views/view_spec/view_helpers.html.erb
135
134
  spec/spec/rails/example/assigns_hash_proxy_spec.rb
136
135
  spec/spec/rails/example/configuration_spec.rb
137
136
  spec/spec/rails/example/controller_example_group_spec.rb
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ Hoe.new('rspec-rails', Spec::Rails::VERSION::STRING) do |p|
13
13
  p.description = "Behaviour Driven Development for Ruby on Rails."
14
14
  p.rubyforge_name = 'rspec'
15
15
  p.developer('RSpec Development Team', 'rspec-devel@rubyforge.org')
16
- p.extra_deps = [["rspec","1.2.4"],["rack",">=0.4.0"]]
16
+ p.extra_deps = [["rspec","1.2.5"],["rack",">=0.4.0"]]
17
17
  p.extra_dev_deps = [["cucumber",">= 0.2.2"]]
18
18
  p.remote_rdoc_dir = "rspec-rails/#{Spec::Rails::VERSION::STRING}"
19
19
  p.history_file = 'History.rdoc'
@@ -65,7 +65,7 @@ Cucumber::Rake::Task.new
65
65
  task :default => [:features]
66
66
 
67
67
  namespace :update do
68
- desc "update the manfest"
68
+ desc "update the manifest"
69
69
  task :manifest do
70
70
  system %q[touch Manifest.txt; rake check_manifest | grep -v "(in " | patch]
71
71
  end
@@ -98,7 +98,7 @@ namespace :spec do
98
98
  ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
99
99
  ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
100
100
  ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
101
- ::STATS_DIRECTORIES << %w(Routing\ specs spec/lib) if File.exist?('spec/routing')
101
+ ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
102
102
  ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
103
103
  ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
104
104
  ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
@@ -162,4 +162,4 @@ namespace :spec do
162
162
  end
163
163
  end
164
164
 
165
- end
165
+ end
@@ -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 %>.should_receive(: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 %>.should_receive(: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 %>.should_receive(: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 %>.should_receive(: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,7 +42,7 @@ 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 %>.should_receive(: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
@@ -70,7 +70,7 @@ describe <%= controller_class_name %>Controller do
70
70
 
71
71
  end
72
72
 
73
- describe "PUT udpate" do
73
+ describe "PUT update" do
74
74
 
75
75
  describe "with valid params" do
76
76
  it "updates the requested <%= file_name %>" do
@@ -47,6 +47,19 @@ module Spec
47
47
  # end
48
48
  # end
49
49
  class ViewExampleGroup < FunctionalExampleGroup
50
+ if ActionView::Base.respond_to?(:load_helpers) # Rails 2.0.x
51
+ ActionView::Helpers.constants.each do |name|
52
+ const = ActionView::Helpers.const_get(name)
53
+ include const if name.include?("Helper") && Module === const
54
+ end
55
+ elsif ActionView::Base.respond_to?(:helper_modules) # Rails 2.1.x
56
+ ActionView::Base.helper_modules.each do |helper_module|
57
+ include helper_module
58
+ end
59
+ else # Rails 2.2.x
60
+ include ActionView::Helpers
61
+ end
62
+
50
63
  tests ViewExampleGroupController
51
64
  class << self
52
65
  def inherited(klass) # :nodoc:
@@ -5,11 +5,12 @@ module Spec # :nodoc:
5
5
  module Matchers
6
6
 
7
7
  class AssertSelect #:nodoc:
8
-
9
- def initialize(assertion, spec_scope, *args, &block)
10
- @assertion = assertion
8
+ attr_reader :options
9
+
10
+ def initialize(selector_assertion, spec_scope, *args, &block)
11
+ @args, @options = args_and_options(args)
11
12
  @spec_scope = spec_scope
12
- @args = args
13
+ @selector_assertion = selector_assertion
13
14
  @block = block
14
15
  end
15
16
 
@@ -21,7 +22,7 @@ module Spec # :nodoc:
21
22
  end
22
23
 
23
24
  begin
24
- @spec_scope.__send__(@assertion, *@args, &@block)
25
+ @spec_scope.__send__(@selector_assertion, *@args, &@block)
25
26
  true
26
27
  rescue ::Test::Unit::AssertionFailedError => @error
27
28
  false
@@ -35,7 +36,7 @@ module Spec # :nodoc:
35
36
  {
36
37
  :assert_select => "have tag#{format_args(*@args)}",
37
38
  :assert_select_email => "send email#{format_args(*@args)}",
38
- }[@assertion]
39
+ }[@selector_assertion]
39
40
  end
40
41
 
41
42
  private
@@ -54,11 +55,13 @@ module Spec # :nodoc:
54
55
 
55
56
  def doc_from(response_or_text)
56
57
  response_or_text.extend TestResponseOrString
57
- markup = response_or_text.body if response_or_text.test_response?
58
- markup = response_or_text if response_or_text.string?
59
- HTML::Document.new(markup, false, true).root if markup
58
+ if response_or_text.test_response?
59
+ HTML::Document.new(response_or_text.body, @options[:strict], @options[:xml]).root
60
+ elsif response_or_text.string?
61
+ HTML::Document.new(response_or_text, @options[:strict], @options[:xml]).root
62
+ end
60
63
  end
61
-
64
+
62
65
  def format_args(*args)
63
66
  args.empty? ? "" : "(#{arg_list(*args)})"
64
67
  end
@@ -69,6 +72,16 @@ module Spec # :nodoc:
69
72
  end.join(", ")
70
73
  end
71
74
 
75
+ def args_and_options(args)
76
+ opts = {:xml => false, :strict => false}
77
+ if args.last.is_a?(::Hash)
78
+ opts[:strict] = args.last.delete(:strict) unless args.last[:strict].nil?
79
+ opts[:xml] = args.last.delete(:xml) unless args.last[:xml].nil?
80
+ args.pop if args.last.empty?
81
+ end
82
+ return [args, opts]
83
+ end
84
+
72
85
  end
73
86
 
74
87
  # :call-seq:
@@ -78,13 +91,20 @@ module Spec # :nodoc:
78
91
  # wrapper for assert_select with additional support for using
79
92
  # css selectors to set expectation on Strings. Use this in
80
93
  # helper specs, for example, to set expectations on the results
81
- # of helper methods.
94
+ # of helper methods. Also allow specification of how the
95
+ # response is parsed using the options :xml and :strict options.
96
+ # By default, these options are set to false.
82
97
  #
83
98
  # == Examples
84
99
  #
85
100
  # # in a controller spec
86
101
  # response.should have_tag("div", "some text")
87
102
  #
103
+ # # to force xml and/or strict parsing of the response
104
+ # response.should have_tag("div", "some text", :xml => true)
105
+ # response.should have_tag("div", "some text", :strict => true)
106
+ # response.should have_tag("div", "some text", :xml => true, :strict => false)
107
+ #
88
108
  # # in a helper spec (person_address_tag is a method in the helper)
89
109
  # person_address_tag.should have_tag("input#person_address")
90
110
  #
@@ -101,6 +121,7 @@ module Spec # :nodoc:
101
121
  #
102
122
  # see documentation for assert_select at http://api.rubyonrails.org/
103
123
  def with_tag(*args, &block)
124
+ args = prepare_args(args, @__current_scope_for_assert_select)
104
125
  @__current_scope_for_assert_select.should have_tag(*args, &block)
105
126
  end
106
127
 
@@ -112,6 +133,7 @@ module Spec # :nodoc:
112
133
  #
113
134
  # see documentation for assert_select at http://api.rubyonrails.org/
114
135
  def without_tag(*args, &block)
136
+ args = prepare_args(args, @__current_scope_for_assert_select)
115
137
  @__current_scope_for_assert_select.should_not have_tag(*args, &block)
116
138
  end
117
139
 
@@ -141,6 +163,18 @@ module Spec # :nodoc:
141
163
  def with_encoded(*args, &block)
142
164
  should AssertSelect.new(:assert_select_encoded, self, *args, &block)
143
165
  end
166
+
167
+ private
168
+
169
+ def prepare_args(args, current_scope = nil)
170
+ return args if current_scope.nil?
171
+ defaults = current_scope.options || {:strict => false, :xml => false}
172
+ args << {} unless args.last.is_a?(::Hash)
173
+ args.last[:strict] = defaults[:strict] if args.last[:strict].nil?
174
+ args.last[:xml] = defaults[:xml] if args.last[:xml].nil?
175
+ args
176
+ end
177
+
144
178
  end
145
179
  end
146
180
  end
@@ -102,7 +102,12 @@ module Spec
102
102
  )
103
103
  )
104
104
 
105
- dispatcher.cleanup_application if dispatcher.respond_to?(:cleanup_application)
105
+ if ::ActionController::Dispatcher.respond_to?(:cleanup_application)
106
+ ::ActionController::Dispatcher.cleanup_application
107
+ else
108
+ dispatcher.cleanup_application
109
+ end
110
+
106
111
  end
107
112
 
108
113
  def in_memory_database?
@@ -4,7 +4,7 @@ module Spec # :nodoc:
4
4
  unless defined? MAJOR
5
5
  MAJOR = 1
6
6
  MINOR = 2
7
- TINY = 4
7
+ TINY = 5
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
10
10
 
@@ -0,0 +1 @@
1
+ <span><%= link_to "edit", "this_is_the_link" %></span>
@@ -333,3 +333,17 @@ describe "bug http://rspec.lighthouseapp.com/projects/5645/tickets/510", :type =
333
333
  end
334
334
  end
335
335
  end
336
+
337
+ describe "bug https://rspec.lighthouseapp.com/projects/5645/tickets/787", :type => :view do
338
+ describe "a view example checking a link" do
339
+ it "should have access to link_to" do
340
+ render "view_spec/view_helpers"
341
+ response.body.should include(link_to("edit", "this_is_the_link"))
342
+ end
343
+
344
+ it "should use link_to within have_tag" do
345
+ render "view_spec/view_helpers"
346
+ response.body.should have_tag("span", :html => link_to("edit", "this_is_the_link"))
347
+ end
348
+ end
349
+ end
@@ -83,6 +83,12 @@ describe "should have_tag", :type => :controller do
83
83
  controller_name :assert_select
84
84
  integrate_views
85
85
 
86
+ it "should not care about the XML setting on HTML with unclosed singletons when using a response" do
87
+ render_html %Q{<table id="1"><tr><td><img src="image.png" alt="image">Hello</td></tr><tr><td></td></tr><tr><td>World</td></tr></table>}
88
+ response.should have_tag("tr", 3)
89
+ response.should have_tag("tr", 3, :xml => true)
90
+ end
91
+
86
92
  it "should find specific numbers of elements" do
87
93
  render_html %Q{<div id="1"></div><div id="2"></div>}
88
94
  response.should have_tag( "div" )
@@ -706,6 +712,26 @@ describe "string.should have_tag", :type => :helper do
706
712
  end
707
713
  end.should raise_error(SpecFailed)
708
714
  end
715
+
716
+ it "should raise when using an HTML string with unclosed singleton tags when using the XML parsing setting" do
717
+ lambda do
718
+ %Q{<table id="1"><tr><td><img src="image.png" alt="image">Hello</td></tr><tr><td></td></tr><tr><td>World</td></tr></table>}.
719
+ should have_tag("tr", 3, :xml => true)
720
+ end.should raise_error
721
+ end
722
+
723
+ it "should find the specific number of elements regardless of unclosed singletons in a HTML string" do
724
+ %Q{<table id="1"><tr><td><img src="image.png" alt="image">Hello</td></tr><tr><td></td></tr><tr><td>World</td></tr></table>}.
725
+ should have_tag("tr", 3)
726
+ end
727
+
728
+ it "should find nested tags in an HTML string regardless unclosed singletons" do
729
+ %Q{<table id="1"><tr><td><img src="image.png" alt="image">Hello</td></tr><tr><td></td></tr><tr><td>World</td></tr></table>}.
730
+ should have_tag("table") do
731
+ with_tag('tr',3)
732
+ end
733
+ end
734
+
709
735
  end
710
736
 
711
737
  describe "have_tag", :type => :controller do
metadata CHANGED
@@ -1,15 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - RSpec Development Team
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRQwEgYDVQQDDAtyc3Bl
14
+ Yy1kZXZlbDEZMBcGCgmSJomT8ixkARkWCXJ1Ynlmb3JnZTETMBEGCgmSJomT8ixk
15
+ ARkWA29yZzAeFw0wOTA0MjgyMDQ5NDVaFw0xMDA0MjgyMDQ5NDVaMEYxFDASBgNV
16
+ BAMMC3JzcGVjLWRldmVsMRkwFwYKCZImiZPyLGQBGRYJcnVieWZvcmdlMRMwEQYK
17
+ CZImiZPyLGQBGRYDb3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
18
+ vFsOmL+2dKD2pskbJlzUvH/NZXL8oFy//5xssQydCbiv4Bx/PSs4JiL12/Rl4OjK
19
+ j+da8ml/8QqzoJqQwSo4T/wRamXd20MKgtn9K+MQ30wby6i0Ti/r85f3XW14Of+K
20
+ OwCoQvzf/kDNpyKYymkMzSdu6nT8GmgjEUpe8SAhwTuY6J/a/oCM0Eu7bFQs/u2f
21
+ B7r6V82E4WrxWy9bPUkUK9gk89HK7H605G6xoKjNiLPTz8v+TdZfNc0Cx94n+GT7
22
+ i/aaSs5lhJ0POB2dcbjvx+mCu+Qy7SbLH08wv8Q0oDlQPNkdgDwBRE+S3N44qOYj
23
+ AAxpF+EMI7NYzcYNETt5TQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
+ sDAdBgNVHQ4EFgQUZFSx0Rt8FU0c2CpTa5gKgMDEXl8wDQYJKoZIhvcNAQEFBQAD
25
+ ggEBALP3T9ws/3qAEZxbK2ZVvebb76FrZjJSxVD/kJqbrAgfZXe0VcpF3c/nT7V7
26
+ 983CvtPhIOBR7dZy+vIm+KPhuD2EraJHuPsW3xatVdxSGGHzPjm13X1TKjDCreb1
27
+ RZMEV+PAdjHdcPvHjg2HI3yM7SB0LhvS/iTylB2vrqyhd3Cgq6dgE9hA+db2r4h+
28
+ du+khTSJ/yAl0IkhpcGNoXI/L5VQXJMgg/lRwmfQl4nqrVN9co3CPciM13L3Kz24
29
+ 7XHWIHZLt6PzpDxMa4RYOeFx0cgxH3Su/hFc086K0Y3BEWSmg+nF/2eCpu7Not1q
30
+ rxjzEkfOKoy3oCfGDf8/ZQyQaJo=
31
+ -----END CERTIFICATE-----
11
32
 
12
- date: 2009-04-13 00:00:00 -03:00
33
+ date: 2009-04-29 00:00:00 -05:00
13
34
  default_executable:
14
35
  dependencies:
15
36
  - !ruby/object:Gem::Dependency
@@ -20,7 +41,7 @@ dependencies:
20
41
  requirements:
21
42
  - - "="
22
43
  - !ruby/object:Gem::Version
23
- version: 1.2.4
44
+ version: 1.2.5
24
45
  version:
25
46
  - !ruby/object:Gem::Dependency
26
47
  name: rack
@@ -75,7 +96,6 @@ files:
75
96
  - Upgrade.rdoc
76
97
  - features/step_definitions/people.rb
77
98
  - features/support/env.rb
78
- - features/transactions/transactions_should_rollback.feature
79
99
  - generators/rspec/CHANGES
80
100
  - generators/rspec/rspec_generator.rb
81
101
  - generators/rspec/templates/previous_failures.txt
@@ -138,7 +158,6 @@ files:
138
158
  - lib/spec/rails/matchers/render_template.rb
139
159
  - lib/spec/rails/mocks.rb
140
160
  - lib/spec/rails/spec_server.rb
141
- - lib/spec/rails/story_adapter.rb
142
161
  - lib/spec/rails/version.rb
143
162
  - spec/autotest/mappings_spec.rb
144
163
  - spec/rails_suite.rb
@@ -199,6 +218,7 @@ files:
199
218
  - spec/resources/views/view_spec/template_with_partial.html.erb
200
219
  - spec/resources/views/view_spec/template_with_partial_using_collection.html.erb
201
220
  - spec/resources/views/view_spec/template_with_partial_with_array.html.erb
221
+ - spec/resources/views/view_spec/view_helpers.html.erb
202
222
  - spec/spec/rails/example/assigns_hash_proxy_spec.rb
203
223
  - spec/spec/rails/example/configuration_spec.rb
204
224
  - spec/spec/rails/example/controller_example_group_spec.rb
@@ -233,10 +253,12 @@ files:
233
253
  - spec/spec_helper.rb
234
254
  has_rdoc: true
235
255
  homepage: http://rspec.info
256
+ licenses: []
257
+
236
258
  post_install_message: |
237
259
  **************************************************
238
260
 
239
- Thank you for installing rspec-rails-1.2.4
261
+ Thank you for installing rspec-rails-1.2.5
240
262
 
241
263
  If you are upgrading, do this in each of your rails apps
242
264
  that you want to upgrade:
@@ -268,9 +290,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
290
  requirements: []
269
291
 
270
292
  rubyforge_project: rspec
271
- rubygems_version: 1.3.1
293
+ rubygems_version: 1.3.2
272
294
  signing_key:
273
- specification_version: 2
274
- summary: rspec-rails 1.2.4
295
+ specification_version: 3
296
+ summary: rspec-rails 1.2.5
275
297
  test_files: []
276
298
 
@@ -0,0 +1 @@
1
+ '�\�e���Fl����ě3U�*��b�Q�v����2�a� ���1���e��k��G��_Y&���wE�x�Y�6�:Z�͎�vkK��/�C�23�NF;(4�Q�5�d҅gs�q��Ʋ"�3Ԗā1-� Ckf;���r����,�C�k���:���8���U��vG[��^��n�m~�ݾE�5:#g՛��i�G1�b�/i�h3K�f���d�N�N}l����c/W�f�Yie7�����<�TK����
@@ -1,16 +0,0 @@
1
- Story: transactions should rollback in plain text
2
- As an RSpec/Rails Story author
3
- I want transactions to roll back between scenarios in plain text
4
- So that I can have confidence in the state of the database
5
-
6
- Scenario: add one Person
7
- When I add a Person
8
- Then there should be one person
9
-
10
- Scenario: add one Person for the second time
11
- When I add a Person
12
- Then there should be one person
13
-
14
- Scenario: add yet another person
15
- When I add a Person
16
- Then there should be one person
@@ -1,79 +0,0 @@
1
- # WARNING - THIS IS PURELY EXPERIMENTAL AT THIS POINT
2
- # Courtesy of Brian Takita and Yurii Rashkovskii
3
-
4
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. .. rspec lib])
5
- if defined?(ActiveRecord::Base)
6
- require 'test_help'
7
- else
8
- require 'action_controller/test_process'
9
- require 'action_controller/integration'
10
- end
11
- require 'test/unit/testresult'
12
- require 'spec'
13
- require 'spec/rails'
14
-
15
- Test::Unit.run = true
16
-
17
- ActionController::Integration::Session.__send__ :include, Spec::Matchers
18
- ActionController::Integration::Session.__send__ :include, Spec::Rails::Matchers
19
-
20
- class RailsStory < ActionController::IntegrationTest
21
- if defined?(ActiveRecord::Base)
22
- self.use_transactional_fixtures = true
23
- else
24
- def self.fixture_table_names; []; end # Workaround for projects that don't use ActiveRecord
25
- end
26
-
27
- def initialize #:nodoc:
28
- # TODO - eliminate this hack, which is here to stop
29
- # Rails Stories from dumping the example summary.
30
- Spec::Runner::Options.class_eval do
31
- def examples_should_be_run?
32
- false
33
- end
34
- end
35
- @_result = Test::Unit::TestResult.new
36
- end
37
- end
38
-
39
- class ActiveRecordSafetyListener
40
- include Singleton
41
- def scenario_started(*args)
42
- if defined?(ActiveRecord::Base)
43
- if ActiveRecord::Base.connection.respond_to?(:increment_open_transactions)
44
- ActiveRecord::Base.connection.increment_open_transactions
45
- else
46
- ActiveRecord::Base.__send__ :increment_open_transactions
47
- end
48
- end
49
- ActiveRecord::Base.connection.begin_db_transaction
50
- end
51
-
52
- def scenario_succeeded(*args)
53
- if defined?(ActiveRecord::Base)
54
- ActiveRecord::Base.connection.rollback_db_transaction
55
- if ActiveRecord::Base.connection.respond_to?(:decrement_open_transactions)
56
- ActiveRecord::Base.connection.decrement_open_transactions
57
- else
58
- ActiveRecord::Base.__send__ :decrement_open_transactions
59
- end
60
- end
61
- end
62
- alias :scenario_pending :scenario_succeeded
63
- alias :scenario_failed :scenario_succeeded
64
- end
65
-
66
- class Spec::Story::Runner::ScenarioRunner
67
- def initialize
68
- @listeners = [ActiveRecordSafetyListener.instance]
69
- end
70
- end
71
-
72
- class Spec::Story::GivenScenario
73
- def perform(instance, name = nil)
74
- scenario = Spec::Story::Runner::StoryRunner.scenario_from_current_story @name
75
- runner = Spec::Story::Runner::ScenarioRunner.new
76
- runner.instance_variable_set(:@listeners,[])
77
- runner.run(scenario, instance)
78
- end
79
- end