dchelimsky-rspec-rails 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/History.txt +63 -0
  2. data/Manifest.txt +158 -0
  3. data/README.txt +81 -0
  4. data/Rakefile +38 -0
  5. data/UPGRADE +7 -0
  6. data/generators/rspec/CHANGES +1 -0
  7. data/generators/rspec/rspec_generator.rb +40 -0
  8. data/generators/rspec/templates/all_stories.rb +4 -0
  9. data/generators/rspec/templates/previous_failures.txt +0 -0
  10. data/generators/rspec/templates/rcov.opts +2 -0
  11. data/generators/rspec/templates/rspec.rake +132 -0
  12. data/generators/rspec/templates/script/autospec +3 -0
  13. data/generators/rspec/templates/script/spec +4 -0
  14. data/generators/rspec/templates/script/spec_server +116 -0
  15. data/generators/rspec/templates/spec.opts +4 -0
  16. data/generators/rspec/templates/spec_helper.rb +47 -0
  17. data/generators/rspec/templates/stories_helper.rb +3 -0
  18. data/generators/rspec_controller/USAGE +33 -0
  19. data/generators/rspec_controller/rspec_controller_generator.rb +49 -0
  20. data/generators/rspec_controller/templates/controller_spec.rb +25 -0
  21. data/generators/rspec_controller/templates/helper_spec.rb +11 -0
  22. data/generators/rspec_controller/templates/view_spec.rb +12 -0
  23. data/generators/rspec_default_values.rb +19 -0
  24. data/generators/rspec_model/USAGE +18 -0
  25. data/generators/rspec_model/rspec_model_generator.rb +35 -0
  26. data/generators/rspec_model/templates/model_spec.rb +15 -0
  27. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
  28. data/generators/rspec_scaffold/templates/controller_spec.rb +173 -0
  29. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +26 -0
  30. data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  31. data/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
  32. data/generators/rspec_scaffold/templates/new_erb_spec.rb +26 -0
  33. data/generators/rspec_scaffold/templates/routing_spec.rb +59 -0
  34. data/generators/rspec_scaffold/templates/show_erb_spec.rb +23 -0
  35. data/init.rb +9 -0
  36. data/lib/autotest/discover.rb +1 -0
  37. data/lib/autotest/rails_rspec.rb +76 -0
  38. data/lib/spec/rails/example/assigns_hash_proxy.rb +37 -0
  39. data/lib/spec/rails/example/controller_example_group.rb +256 -0
  40. data/lib/spec/rails/example/cookies_proxy.rb +25 -0
  41. data/lib/spec/rails/example/functional_example_group.rb +87 -0
  42. data/lib/spec/rails/example/helper_example_group.rb +166 -0
  43. data/lib/spec/rails/example/model_example_group.rb +14 -0
  44. data/lib/spec/rails/example/rails_example_group.rb +33 -0
  45. data/lib/spec/rails/example/render_observer.rb +93 -0
  46. data/lib/spec/rails/example/view_example_group.rb +183 -0
  47. data/lib/spec/rails/example.rb +47 -0
  48. data/lib/spec/rails/extensions/action_controller/base.rb +14 -0
  49. data/lib/spec/rails/extensions/action_controller/rescue.rb +21 -0
  50. data/lib/spec/rails/extensions/action_controller/test_response.rb +11 -0
  51. data/lib/spec/rails/extensions/action_view/base.rb +31 -0
  52. data/lib/spec/rails/extensions/active_record/base.rb +30 -0
  53. data/lib/spec/rails/extensions/object.rb +5 -0
  54. data/lib/spec/rails/extensions/spec/example/configuration.rb +71 -0
  55. data/lib/spec/rails/extensions/spec/matchers/have.rb +21 -0
  56. data/lib/spec/rails/extensions.rb +12 -0
  57. data/lib/spec/rails/interop/testcase.rb +14 -0
  58. data/lib/spec/rails/matchers/assert_select.rb +131 -0
  59. data/lib/spec/rails/matchers/change.rb +11 -0
  60. data/lib/spec/rails/matchers/have_text.rb +57 -0
  61. data/lib/spec/rails/matchers/include_text.rb +54 -0
  62. data/lib/spec/rails/matchers/redirect_to.rb +113 -0
  63. data/lib/spec/rails/matchers/render_template.rb +90 -0
  64. data/lib/spec/rails/matchers.rb +31 -0
  65. data/lib/spec/rails/mocks.rb +132 -0
  66. data/lib/spec/rails/story_adapter.rb +79 -0
  67. data/lib/spec/rails/version.rb +15 -0
  68. data/lib/spec/rails.rb +15 -0
  69. data/spec/rails/autotest/mappings_spec.rb +36 -0
  70. data/spec/rails/example/assigns_hash_proxy_spec.rb +70 -0
  71. data/spec/rails/example/configuration_spec.rb +83 -0
  72. data/spec/rails/example/controller_isolation_spec.rb +62 -0
  73. data/spec/rails/example/controller_spec_spec.rb +272 -0
  74. data/spec/rails/example/cookies_proxy_spec.rb +74 -0
  75. data/spec/rails/example/example_group_factory_spec.rb +112 -0
  76. data/spec/rails/example/helper_spec_spec.rb +161 -0
  77. data/spec/rails/example/model_spec_spec.rb +18 -0
  78. data/spec/rails/example/shared_behaviour_spec.rb +16 -0
  79. data/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
  80. data/spec/rails/example/view_spec_spec.rb +280 -0
  81. data/spec/rails/extensions/action_controller_rescue_action_spec.rb +54 -0
  82. data/spec/rails/extensions/action_view_base_spec.rb +48 -0
  83. data/spec/rails/extensions/active_record_spec.rb +14 -0
  84. data/spec/rails/interop/testcase_spec.rb +66 -0
  85. data/spec/rails/matchers/assert_select_spec.rb +814 -0
  86. data/spec/rails/matchers/description_generation_spec.rb +37 -0
  87. data/spec/rails/matchers/errors_on_spec.rb +13 -0
  88. data/spec/rails/matchers/have_text_spec.rb +62 -0
  89. data/spec/rails/matchers/include_text_spec.rb +64 -0
  90. data/spec/rails/matchers/redirect_to_spec.rb +209 -0
  91. data/spec/rails/matchers/render_template_spec.rb +176 -0
  92. data/spec/rails/matchers/should_change_spec.rb +15 -0
  93. data/spec/rails/mocks/ar_classes.rb +10 -0
  94. data/spec/rails/mocks/mock_model_spec.rb +106 -0
  95. data/spec/rails/mocks/stub_model_spec.rb +80 -0
  96. data/spec/rails/sample_modified_fixture.rb +8 -0
  97. data/spec/rails/sample_spec.rb +8 -0
  98. data/spec/rails/spec_server_spec.rb +96 -0
  99. data/spec/rails/spec_spec.rb +11 -0
  100. data/spec/rails_suite.rb +7 -0
  101. data/spec/spec_helper.rb +57 -0
  102. data/spec_resources/controllers/action_view_base_spec_controller.rb +2 -0
  103. data/spec_resources/controllers/controller_spec_controller.rb +94 -0
  104. data/spec_resources/controllers/redirect_spec_controller.rb +59 -0
  105. data/spec_resources/controllers/render_spec_controller.rb +30 -0
  106. data/spec_resources/controllers/rjs_spec_controller.rb +58 -0
  107. data/spec_resources/helpers/explicit_helper.rb +38 -0
  108. data/spec_resources/helpers/more_explicit_helper.rb +5 -0
  109. data/spec_resources/helpers/plugin_application_helper.rb +6 -0
  110. data/spec_resources/helpers/view_spec_helper.rb +13 -0
  111. data/spec_resources/views/controller_spec/_partial.rhtml +0 -0
  112. data/spec_resources/views/controller_spec/action_setting_flash_after_session_reset.rhtml +1 -0
  113. data/spec_resources/views/controller_spec/action_setting_flash_before_session_reset.rhtml +1 -0
  114. data/spec_resources/views/controller_spec/action_setting_the_assigns_hash.rhtml +0 -0
  115. data/spec_resources/views/controller_spec/action_with_errors_in_template.rhtml +1 -0
  116. data/spec_resources/views/controller_spec/action_with_template.rhtml +1 -0
  117. data/spec_resources/views/layouts/application.rhtml +0 -0
  118. data/spec_resources/views/layouts/simple.rhtml +0 -0
  119. data/spec_resources/views/objects/_object.html.erb +1 -0
  120. data/spec_resources/views/render_spec/_a_partial.rhtml +0 -0
  121. data/spec_resources/views/render_spec/action_with_alternate_layout.rhtml +0 -0
  122. data/spec_resources/views/render_spec/some_action.js.rjs +1 -0
  123. data/spec_resources/views/render_spec/some_action.rhtml +0 -0
  124. data/spec_resources/views/render_spec/some_action.rjs +1 -0
  125. data/spec_resources/views/rjs_spec/_replacement_partial.rhtml +1 -0
  126. data/spec_resources/views/rjs_spec/hide_div.rjs +1 -0
  127. data/spec_resources/views/rjs_spec/hide_page_element.rjs +1 -0
  128. data/spec_resources/views/rjs_spec/insert_html.rjs +1 -0
  129. data/spec_resources/views/rjs_spec/replace.rjs +1 -0
  130. data/spec_resources/views/rjs_spec/replace_html.rjs +1 -0
  131. data/spec_resources/views/rjs_spec/replace_html_with_partial.rjs +1 -0
  132. data/spec_resources/views/rjs_spec/visual_effect.rjs +1 -0
  133. data/spec_resources/views/rjs_spec/visual_toggle_effect.rjs +1 -0
  134. data/spec_resources/views/tag_spec/no_tags.rhtml +1 -0
  135. data/spec_resources/views/tag_spec/single_div_with_no_attributes.rhtml +1 -0
  136. data/spec_resources/views/tag_spec/single_div_with_one_attribute.rhtml +1 -0
  137. data/spec_resources/views/view_spec/_partial.rhtml +2 -0
  138. data/spec_resources/views/view_spec/_partial_used_twice.rhtml +0 -0
  139. data/spec_resources/views/view_spec/_partial_with_local_variable.rhtml +1 -0
  140. data/spec_resources/views/view_spec/_partial_with_sub_partial.rhtml +1 -0
  141. data/spec_resources/views/view_spec/_spacer.rhtml +1 -0
  142. data/spec_resources/views/view_spec/accessor.rhtml +5 -0
  143. data/spec_resources/views/view_spec/block_helper.rhtml +3 -0
  144. data/spec_resources/views/view_spec/entry_form.rhtml +2 -0
  145. data/spec_resources/views/view_spec/explicit_helper.rhtml +2 -0
  146. data/spec_resources/views/view_spec/foo/show.rhtml +1 -0
  147. data/spec_resources/views/view_spec/implicit_helper.rhtml +2 -0
  148. data/spec_resources/views/view_spec/multiple_helpers.rhtml +3 -0
  149. data/spec_resources/views/view_spec/should_not_receive.rhtml +3 -0
  150. data/spec_resources/views/view_spec/template_with_partial.rhtml +5 -0
  151. data/spec_resources/views/view_spec/template_with_partial_using_collection.rhtml +3 -0
  152. data/spec_resources/views/view_spec/template_with_partial_with_array.rhtml +1 -0
  153. data/stories/all.rb +10 -0
  154. data/stories/configuration/stories.rb +5 -0
  155. data/stories/helper.rb +6 -0
  156. data/stories/steps/people.rb +8 -0
  157. data/stories/transactions_should_rollback +15 -0
  158. data/stories/transactions_should_rollback.rb +25 -0
  159. metadata +232 -0
@@ -0,0 +1,132 @@
1
+ module Spec
2
+ module Rails
3
+
4
+ class IllegalDataAccessException < StandardError; end
5
+
6
+ module Mocks
7
+
8
+ # Creates a mock object instance for a +model_class+ with common
9
+ # methods stubbed out. Additional methods may be easily stubbed (via
10
+ # add_stubs) if +stubs+ is passed.
11
+ def mock_model(model_class, options_and_stubs = {})
12
+ id = options_and_stubs[:id] || next_id
13
+ options_and_stubs = options_and_stubs.reverse_merge({
14
+ :id => id,
15
+ :to_param => id.to_s,
16
+ :new_record? => false,
17
+ :errors => stub("errors", :count => 0)
18
+ })
19
+ m = mock("#{model_class.name}_#{id}", options_and_stubs)
20
+ m.send(:__mock_proxy).instance_eval <<-CODE
21
+ def @target.as_new_record
22
+ self.stub!(:id).and_return nil
23
+ self.stub!(:to_param).and_return nil
24
+ self.stub!(:new_record?).and_return true
25
+ self
26
+ end
27
+ def @target.is_a?(other)
28
+ #{model_class}.ancestors.include?(other)
29
+ end
30
+ def @target.kind_of?(other)
31
+ #{model_class}.ancestors.include?(other)
32
+ end
33
+ def @target.instance_of?(other)
34
+ other == #{model_class}
35
+ end
36
+ def @target.class
37
+ #{model_class}
38
+ end
39
+ CODE
40
+ yield m if block_given?
41
+ m
42
+ end
43
+
44
+ module ModelStubber
45
+ def connection
46
+ raise Spec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
47
+ end
48
+ def new_record?
49
+ id.nil?
50
+ end
51
+ def as_new_record
52
+ self.id = nil
53
+ self
54
+ end
55
+ end
56
+
57
+ # :call-seq:
58
+ # stub_model(Model)
59
+ # stub_model(Model).as_new_record
60
+ # stub_model(Model, hash_of_stubs)
61
+ # stub_model(Model, instance_variable_name, hash_of_stubs)
62
+ #
63
+ # Creates an instance of +Model+ that is prohibited from accessing the
64
+ # database*. For each key in +hash_of_stubs+, if the model has a
65
+ # matching attribute (determined by asking it) are simply assigned the
66
+ # submitted values. If the model does not have a matching attribute, the
67
+ # key/value pair is assigned as a stub return value using RSpec's
68
+ # mocking/stubbing framework.
69
+ #
70
+ # <tt>new_record?</tt> is overridden to return the result of id.nil?
71
+ # This means that by default new_record? will return false. If you want
72
+ # the object to behave as a new record, sending it +as_new_record+ will
73
+ # set the id to nil. You can also explicitly set :id => nil, in which
74
+ # case new_record? will return true, but using +as_new_record+ makes the
75
+ # example a bit more descriptive.
76
+ #
77
+ # While you can use stub_model in any example (model, view, controller,
78
+ # helper), it is especially useful in view examples, which are
79
+ # inherently more state-based than interaction-based.
80
+ #
81
+ # == Database Independence
82
+ #
83
+ # +stub_model+ does not make your examples entirely
84
+ # database-independent. It does not stop the model class itself from
85
+ # loading up its columns from the database. It just prevents data access
86
+ # from the object itself. To completely decouple from the database, take
87
+ # a look at libraries like unit_record or NullDB.
88
+ #
89
+ # == Examples
90
+ #
91
+ # stub_model(Person)
92
+ # stub_model(Person).as_new_record
93
+ # stub_model(Person, :id => 37)
94
+ # stub_model(Person) do |person|
95
+ # person.first_name = "David"
96
+ # end
97
+ def stub_model(model_class, stubs={})
98
+ stubs = {:id => next_id}.merge(stubs)
99
+ returning model_class.new do |model|
100
+ model.id = stubs.delete(:id)
101
+ model.extend ModelStubber
102
+ stubs.each do |k,v|
103
+ if model.has_attribute?(k)
104
+ model[k] = stubs.delete(k)
105
+ end
106
+ end
107
+ add_stubs(model, stubs)
108
+ yield model if block_given?
109
+ end
110
+ end
111
+
112
+ #--
113
+ # TODO - Shouldn't this just be an extension of stub! ??
114
+ # - object.stub!(:method => return_value, :method2 => return_value2, :etc => etc)
115
+ #++
116
+ # Stubs methods on +object+ (if +object+ is a symbol or string a new mock
117
+ # with that name will be created). +stubs+ is a Hash of +method=>value+
118
+ def add_stubs(object, stubs = {}) #:nodoc:
119
+ m = [String, Symbol].index(object.class) ? mock(object.to_s) : object
120
+ stubs.each {|k,v| m.stub!(k).and_return(v)}
121
+ m
122
+ end
123
+
124
+ private
125
+ @@model_id = 1000
126
+ def next_id
127
+ @@model_id += 1
128
+ end
129
+
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,79 @@
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
@@ -0,0 +1,15 @@
1
+ module Spec
2
+ module Rails
3
+ module VERSION #:nodoc:
4
+ unless defined? MAJOR
5
+ MAJOR = 1
6
+ MINOR = 1
7
+ TINY = 6
8
+
9
+ STRING = [MAJOR, MINOR, TINY].join('.')
10
+
11
+ SUMMARY = "rspec-rails #{STRING}"
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/spec/rails.rb ADDED
@@ -0,0 +1,15 @@
1
+ silence_warnings { RAILS_ENV = "test" }
2
+
3
+ require_dependency 'application'
4
+ require 'action_controller/test_process'
5
+ require 'action_controller/integration'
6
+ require 'active_record/fixtures' if defined?(ActiveRecord::Base)
7
+ require 'test/unit'
8
+
9
+ require 'spec'
10
+
11
+ require 'spec/rails/matchers'
12
+ require 'spec/rails/mocks'
13
+ require 'spec/rails/example'
14
+ require 'spec/rails/extensions'
15
+ require 'spec/rails/interop/testcase'
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. lib autotest rails_rspec])
3
+ require File.join(File.dirname(__FILE__), *%w[.. .. .. .. rspec spec autotest autotest_matchers])
4
+
5
+ describe Autotest::RailsRspec, "file mapping" do
6
+ before(:each) do
7
+ @autotest = Autotest::RailsRspec.new
8
+ @autotest.hook :initialize
9
+ end
10
+
11
+ it "should map model example to model" do
12
+ @autotest.should map_specs(['spec/models/thing_spec.rb']).
13
+ to('app/models/thing.rb')
14
+ end
15
+
16
+ it "should map controller example to controller" do
17
+ @autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
18
+ to('app/controllers/things_controller.rb')
19
+ end
20
+
21
+ it "should map view.rhtml" do
22
+ @autotest.should map_specs(['spec/views/things/index.rhtml_spec.rb']).
23
+ to('app/views/things/index.rhtml')
24
+ end
25
+
26
+ it "should map view.rhtml with underscores in example filename" do
27
+ @autotest.should map_specs(['spec/views/things/index_rhtml_spec.rb']).
28
+ to('app/views/things/index.rhtml')
29
+ end
30
+
31
+ it "should map view.html.erb" do
32
+ @autotest.should map_specs(['spec/views/things/index.html.erb_spec.rb']).
33
+ to('app/views/things/index.html.erb')
34
+ end
35
+
36
+ end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "AssignsHashProxy" do
4
+ def orig_assigns
5
+ @object.assigns
6
+ end
7
+
8
+ before(:each) do
9
+ @object = Class.new do
10
+ attr_accessor :assigns
11
+ end.new
12
+ @object.assigns = Hash.new
13
+ @proxy = Spec::Rails::Example::AssignsHashProxy.new self do
14
+ @object
15
+ end
16
+ end
17
+
18
+ it "should set ivars on object using string" do
19
+ @proxy['foo'] = 'bar'
20
+ @object.instance_eval{@foo}.should == 'bar'
21
+ end
22
+
23
+ it "should set ivars on object using symbol" do
24
+ @proxy[:foo] = 'bar'
25
+ @object.instance_eval{@foo}.should == 'bar'
26
+ end
27
+
28
+ it "should access object's assigns with a string" do
29
+ @object.assigns['foo'] = 'bar'
30
+ @proxy[:foo].should == 'bar'
31
+ end
32
+
33
+ it "should access object's assigns with a symbol" do
34
+ @object.assigns['foo'] = 'bar'
35
+ @proxy[:foo].should == 'bar'
36
+ end
37
+
38
+ it "iterates through each element like a Hash" do
39
+ values = {
40
+ 'foo' => 1,
41
+ 'bar' => 2,
42
+ 'baz' => 3
43
+ }
44
+ @proxy['foo'] = values['foo']
45
+ @proxy['bar'] = values['bar']
46
+ @proxy['baz'] = values['baz']
47
+
48
+ @proxy.each do |key, value|
49
+ key.should == key
50
+ value.should == values[key]
51
+ end
52
+ end
53
+
54
+ it "deletes the element of passed in key" do
55
+ @object.assigns['foo'] = 'bar'
56
+ @proxy.delete('foo').should == 'bar'
57
+ @proxy['foo'].should be_nil
58
+ end
59
+
60
+ it "detects the presence of a key" do
61
+ @object.assigns['foo'] = 'bar'
62
+ @proxy.has_key?('foo').should == true
63
+ @proxy.has_key?('bar').should == false
64
+ end
65
+
66
+ it "should expose values set in example" do
67
+ @proxy[:foo] = 'bar'
68
+ @proxy[:foo].should == 'bar'
69
+ end
70
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module Example
5
+ describe Configuration, :shared => true do
6
+ before(:each) { @config = Configuration.new }
7
+ end
8
+
9
+ describe Configuration, "#use_transactional_fixtures" do
10
+ it_should_behave_like "Spec::Example::Configuration"
11
+
12
+ it "should return Test::Unit::TestCase.use_transactional_fixtures" do
13
+ @config.use_transactional_fixtures.should == Test::Unit::TestCase.use_transactional_fixtures
14
+ end
15
+
16
+ it "should set Test::Unit::TestCase.use_transactional_fixtures to false" do
17
+ Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
18
+ example_group.should_receive(:use_transactional_fixtures=).with(false)
19
+ end
20
+ @config.use_transactional_fixtures = false
21
+ end
22
+
23
+ it "should set Test::Unit::TestCase.use_transactional_fixtures to true" do
24
+ Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
25
+ example_group.should_receive(:use_transactional_fixtures=).with(true)
26
+ end
27
+ @config.use_transactional_fixtures = true
28
+ end
29
+ end
30
+
31
+ describe Configuration, "#use_instantiated_fixtures" do
32
+ it_should_behave_like "Spec::Example::Configuration"
33
+
34
+ it "should return Test::Unit::TestCase.use_transactional_fixtures" do
35
+ @config.use_instantiated_fixtures.should == Test::Unit::TestCase.use_instantiated_fixtures
36
+ end
37
+
38
+ it "should set Test::Unit::TestCase.use_instantiated_fixtures to false" do
39
+ Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
40
+ example_group.should_receive(:use_instantiated_fixtures=).with(false)
41
+ end
42
+ @config.use_instantiated_fixtures = false
43
+ end
44
+
45
+ it "should set Test::Unit::TestCase.use_instantiated_fixtures to true" do
46
+ Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
47
+ example_group.should_receive(:use_instantiated_fixtures=).with(true)
48
+ end
49
+ @config.use_instantiated_fixtures = true
50
+ end
51
+ end
52
+
53
+ describe Configuration, "#fixture_path" do
54
+ it_should_behave_like "Spec::Example::Configuration"
55
+
56
+ it "should default to RAILS_ROOT + '/spec/fixtures'" do
57
+ @config.fixture_path.should == RAILS_ROOT + '/spec/fixtures'
58
+ Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
59
+ example_group.fixture_path.should == RAILS_ROOT + '/spec/fixtures'
60
+ end
61
+ end
62
+
63
+ it "should set fixture_path" do
64
+ @config.fixture_path = "/new/path"
65
+ @config.fixture_path.should == "/new/path"
66
+ Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
67
+ example_group.fixture_path.should == "/new/path"
68
+ end
69
+ end
70
+ end
71
+
72
+ describe Configuration, "#global_fixtures" do
73
+ it_should_behave_like "Spec::Example::Configuration"
74
+
75
+ it "should set fixtures on TestCase" do
76
+ Configuration::EXAMPLE_GROUP_CLASSES.each do |example_group|
77
+ example_group.should_receive(:fixtures).with(:blah)
78
+ end
79
+ @config.global_fixtures = [:blah]
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'controller_spec_controller'
3
+
4
+ describe "a controller spec running in isolation mode", :type => :controller do
5
+ controller_name :controller_spec
6
+
7
+ it "should not care if the template doesn't exist" do
8
+ get 'some_action'
9
+ response.should be_success
10
+ response.should render_template("template/that/does/not/actually/exist")
11
+ end
12
+
13
+ it "should not care if the template has errors" do
14
+ get 'action_with_errors_in_template'
15
+ response.should be_success
16
+ response.should render_template("action_with_errors_in_template")
17
+ end
18
+ end
19
+
20
+ describe "a controller spec running in integration mode", :type => :controller do
21
+ controller_name :controller_spec
22
+ integrate_views
23
+
24
+ before(:each) do
25
+ controller.class.send(:define_method, :rescue_action) { |e| raise e }
26
+ end
27
+
28
+ it "should render a template" do
29
+ get 'action_with_template'
30
+ response.should be_success
31
+ response.should have_tag('div', 'This is action_with_template.rhtml')
32
+ end
33
+
34
+ it "should choke if the template doesn't exist" do
35
+ error = defined?(ActionController::MissingTemplate) ? ActionController::MissingTemplate : ActionView::MissingTemplate
36
+ lambda { get 'some_action' }.should raise_error(error)
37
+ response.should_not be_success
38
+ end
39
+
40
+ it "should choke if the template has errors" do
41
+ lambda { get 'action_with_errors_in_template' }.should raise_error(ActionView::TemplateError)
42
+ response.should_not be_success
43
+ end
44
+
45
+ describe "nested" do
46
+ it "should render a template" do
47
+ get 'action_with_template'
48
+ response.should be_success
49
+ response.should have_tag('div', 'This is action_with_template.rhtml')
50
+ end
51
+
52
+ describe "with integrate_views turned off" do
53
+ integrate_views false
54
+
55
+ it "should not care if the template doesn't exist" do
56
+ get 'some_action'
57
+ response.should be_success
58
+ response.should render_template("template/that/does/not/actually/exist")
59
+ end
60
+ end
61
+ end
62
+ end