rspec-rails 1.1.12 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +7 -0
- data/History.txt +55 -0
- data/License.txt +1 -1
- data/Manifest.txt +53 -48
- data/README.txt +5 -4
- data/Rakefile +9 -2
- data/TODO.txt +1 -0
- data/Upgrade.markdown +103 -0
- data/generators/rspec/rspec_generator.rb +1 -0
- data/generators/rspec/templates/rspec.rake +134 -111
- data/generators/rspec/templates/script/autospec +1 -0
- data/generators/rspec/templates/script/spec +21 -4
- data/generators/rspec/templates/script/spec_server +34 -107
- data/generators/rspec/templates/spec_helper.rb +1 -1
- data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +13 -17
- data/generators/rspec_scaffold/templates/controller_spec.rb +27 -29
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +2 -2
- data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +2 -2
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +2 -2
- data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +2 -2
- data/lib/spec/rails.rb +10 -9
- data/lib/spec/rails/example.rb +2 -2
- data/lib/spec/rails/example/assigns_hash_proxy.rb +1 -2
- data/lib/spec/rails/example/controller_example_group.rb +117 -123
- data/lib/spec/rails/example/functional_example_group.rb +7 -22
- data/lib/spec/rails/example/helper_example_group.rb +15 -33
- 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/routing_example_group.rb +13 -0
- data/lib/spec/rails/example/routing_helpers.rb +68 -0
- data/lib/spec/rails/example/view_example_group.rb +50 -47
- data/lib/spec/rails/extensions.rb +2 -1
- data/lib/spec/rails/extensions/action_controller/rescue.rb +25 -8
- data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
- data/lib/spec/rails/extensions/action_controller/test_response.rb +4 -3
- data/lib/spec/rails/extensions/action_view/base.rb +9 -9
- data/lib/spec/rails/extensions/active_record/base.rb +39 -23
- data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
- data/lib/spec/rails/extensions/spec/matchers/have.rb +8 -6
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
- data/lib/spec/rails/matchers/ar_be_valid.rb +8 -5
- data/lib/spec/rails/matchers/assert_select.rb +36 -21
- data/lib/spec/rails/matchers/have_text.rb +3 -3
- data/lib/spec/rails/matchers/include_text.rb +4 -4
- data/lib/spec/rails/matchers/redirect_to.rb +30 -19
- data/lib/spec/rails/matchers/render_template.rb +7 -3
- data/lib/spec/rails/mocks.rb +1 -1
- data/lib/spec/rails/spec_server.rb +97 -0
- data/lib/spec/rails/story_adapter.rb +4 -4
- data/lib/spec/rails/version.rb +2 -2
- data/spec/resources/controllers/controller_spec_controller.rb +14 -6
- data/spec/resources/controllers/example.txt +1 -0
- data/spec/resources/controllers/redirect_spec_controller.rb +4 -0
- data/spec/resources/controllers/render_spec_controller.rb +1 -1
- data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
- data/spec/resources/helpers/explicit_helper.rb +1 -1
- data/spec/resources/views/controller_spec/{_partial.rhtml → _partial.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_setting_flash_after_session_reset.rhtml → action_setting_flash_after_session_reset.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_setting_flash_before_session_reset.rhtml → action_setting_flash_before_session_reset.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_setting_the_assigns_hash.rhtml → action_setting_the_assigns_hash.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_with_errors_in_template.rhtml → action_with_errors_in_template.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_with_template.rhtml → action_with_template.html.erb} +0 -0
- data/spec/resources/views/layouts/{application.rhtml → application.html.erb} +0 -0
- data/spec/resources/views/layouts/{simple.rhtml → simple.html.erb} +0 -0
- data/spec/resources/views/render_spec/{_a_partial.rhtml → _a_partial.html.erb} +0 -0
- data/spec/resources/views/render_spec/{action_with_alternate_layout.rhtml → action_with_alternate_layout.html.erb} +0 -0
- data/spec/resources/views/rjs_spec/{_replacement_partial.rhtml → _replacement_partial.html.erb} +0 -0
- data/spec/resources/views/rjs_spec/{hide_div.rjs → hide_div.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{hide_page_element.rjs → hide_page_element.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{insert_html.rjs → insert_html.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{replace.rjs → replace.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{replace_html.rjs → replace_html.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{replace_html_with_partial.rjs → replace_html_with_partial.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{visual_effect.rjs → visual_effect.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{visual_toggle_effect.rjs → visual_toggle_effect.js.rjs} +0 -0
- data/spec/resources/views/tag_spec/{no_tags.rhtml → no_tags.html.erb} +0 -0
- data/spec/resources/views/tag_spec/{single_div_with_no_attributes.rhtml → single_div_with_no_attributes.html.erb} +0 -0
- data/spec/resources/views/tag_spec/{single_div_with_one_attribute.rhtml → single_div_with_one_attribute.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial.rhtml → _partial.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial_used_twice.rhtml → _partial_used_twice.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial_with_local_variable.rhtml → _partial_with_local_variable.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial_with_sub_partial.rhtml → _partial_with_sub_partial.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_spacer.rhtml → _spacer.html.erb} +0 -0
- data/spec/resources/views/view_spec/{accessor.rhtml → accessor.html.erb} +0 -0
- data/spec/resources/views/view_spec/{block_helper.rhtml → block_helper.html.erb} +0 -0
- data/spec/resources/views/view_spec/{entry_form.rhtml → entry_form.html.erb} +0 -0
- data/spec/resources/views/view_spec/{explicit_helper.rhtml → explicit_helper.html.erb} +0 -0
- data/spec/resources/views/view_spec/foo/{show.rhtml → show.html.erb} +0 -0
- data/spec/resources/views/view_spec/{implicit_helper.rhtml → implicit_helper.html.erb} +0 -0
- data/spec/resources/views/view_spec/{multiple_helpers.rhtml → multiple_helpers.html.erb} +0 -0
- data/spec/resources/views/view_spec/{should_not_receive.rhtml → should_not_receive.html.erb} +0 -0
- data/spec/resources/views/view_spec/{template_with_partial.rhtml → template_with_partial.html.erb} +0 -0
- data/spec/resources/views/view_spec/{template_with_partial_using_collection.rhtml → template_with_partial_using_collection.html.erb} +0 -0
- data/spec/resources/views/view_spec/{template_with_partial_with_array.rhtml → template_with_partial_with_array.html.erb} +0 -0
- data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +18 -5
- data/spec/spec/rails/example/configuration_spec.rb +15 -29
- data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +40 -96
- data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
- data/spec/spec/rails/example/error_handling_spec.rb +90 -0
- 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} +45 -13
- data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
- data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
- data/spec/spec/rails/example/shared_routing_example_group_examples.rb +45 -0
- data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +1 -1
- data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +44 -17
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
- data/spec/spec/rails/matchers/assert_select_spec.rb +59 -60
- 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 +224 -189
- data/spec/spec/rails/matchers/render_template_spec.rb +169 -158
- data/spec/spec/rails/spec_server_spec.rb +18 -7
- data/spec/spec_helper.rb +21 -9
- metadata +68 -53
- data/lib/spec/rails/example/rails_example_group.rb +0 -28
- data/lib/spec/rails/extensions/action_controller/base.rb +0 -14
- data/rspec-rails.gemspec +0 -36
- data/spec/resources/views/render_spec/some_action.rjs +0 -1
- data/spec/spec/rails/example/shared_behaviour_spec.rb +0 -16
- data/spec/spec/rails/extensions/action_controller_rescue_action_spec.rb +0 -57
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
|
2
3
|
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
|
3
4
|
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
|
4
5
|
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
|
@@ -1,5 +1,22 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
|
3
|
+
rails_root = File.expand_path(File.dirname(__FILE__) + "/..")
|
4
|
+
rspec_gem_dir = nil
|
5
|
+
Dir["#{rails_root}/vendor/gems/*"].each do |subdir|
|
6
|
+
rspec_gem_dir = subdir if subdir.gsub("#{rails_root}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
|
7
|
+
end
|
8
|
+
rspec_plugin_dir = File.expand_path("#{rails_root}/vendor/plugins/rspec")
|
9
|
+
|
10
|
+
if rspec_gem_dir && (test ?d, rspec_plugin_dir)
|
11
|
+
raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
if rspec_gem_dir
|
15
|
+
$LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
|
16
|
+
elsif File.exist?(rspec_plugin_dir)
|
17
|
+
$LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
require 'spec/autorun'
|
22
|
+
exit ::Spec::Runner::CommandLine.run
|
@@ -1,125 +1,52 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# This is based on Florian Weber's TDDMate
|
10
|
-
module Spec
|
11
|
-
module Runner
|
12
|
-
class RailsSpecServer
|
13
|
-
def run(argv, stderr, stdout)
|
14
|
-
$stdout = stdout
|
15
|
-
$stderr = stderr
|
16
|
-
|
17
|
-
unless ActiveRecord::Base.respond_to?(:clear_reloadable_connections!)
|
18
|
-
base = ActiveRecord::Base
|
19
|
-
def base.clear_reloadable_connections!
|
20
|
-
active_connections.each do |name, conn|
|
21
|
-
if conn.requires_reloading?
|
22
|
-
conn.disconnect!
|
23
|
-
active_connections.delete(name)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
ActiveRecord::Base.clear_reloadable_connections!
|
30
|
-
|
31
|
-
if ActionController.const_defined?(:Dispatcher)
|
32
|
-
dispatcher = ::ActionController::Dispatcher.new($stdout)
|
33
|
-
dispatcher.cleanup_application
|
34
|
-
elsif ::Dispatcher.respond_to?(:reset_application!)
|
35
|
-
::Dispatcher.reset_application!
|
36
|
-
else
|
37
|
-
raise "Application reloading failed"
|
38
|
-
end
|
39
|
-
if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
|
40
|
-
Fixtures.reset_cache
|
41
|
-
end
|
42
|
-
|
43
|
-
if ::ActiveSupport.const_defined?(:Dependencies)
|
44
|
-
::ActiveSupport::Dependencies.mechanism = :load
|
45
|
-
else
|
46
|
-
::Dependencies.mechanism = :load
|
47
|
-
end
|
2
|
+
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
|
3
|
+
rails_root = File.expand_path(File.dirname(__FILE__) + "/..")
|
4
|
+
rspec_rails_gem_dir = nil
|
5
|
+
Dir["#{rails_root}/vendor/gems/*"].each do |subdir|
|
6
|
+
rspec_rails_gem_dir = subdir if subdir.gsub("#{rails_root}/vendor/gems/","") =~ /^(\w+-)?rspec-rails-(\d+)/
|
7
|
+
end
|
8
|
+
rspec_rails_plugin_dir = File.expand_path("#{rails_root}/vendor/plugins/rspec-rails")
|
48
9
|
|
49
|
-
|
50
|
-
|
10
|
+
if rspec_rails_gem_dir && (test ?d, rspec_rails_plugin_dir)
|
11
|
+
raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
|
12
|
+
end
|
51
13
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
14
|
+
if rspec_rails_gem_dir
|
15
|
+
$LOAD_PATH.unshift("#{rspec_rails_gem_dir}/lib")
|
16
|
+
elsif File.exist?(rspec_rails_plugin_dir)
|
17
|
+
$LOAD_PATH.unshift("#{rspec_rails_plugin_dir}/lib")
|
18
|
+
end
|
56
19
|
|
57
|
-
|
58
|
-
|
59
|
-
argv,
|
60
|
-
$stderr,
|
61
|
-
$stdout
|
62
|
-
)
|
63
|
-
)
|
64
|
-
end
|
20
|
+
require 'optparse'
|
21
|
+
require 'spec/rails/spec_server'
|
65
22
|
|
66
|
-
def in_memory_database?
|
67
|
-
ENV["RAILS_ENV"] == "test" and
|
68
|
-
::ActiveRecord::Base.connection.class.to_s == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" and
|
69
|
-
::Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
23
|
puts "Loading Rails environment"
|
75
24
|
|
76
25
|
ENV["RAILS_ENV"] = "test"
|
77
26
|
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
78
|
-
require 'dispatcher'
|
79
27
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
command_line = [ruby, $0, ARGV].flatten.join(' ')
|
85
|
-
exec(command_line)
|
86
|
-
end
|
28
|
+
if Rails::VERSION::STRING >= '2.2' && Rails.configuration.cache_classes
|
29
|
+
warn <<-MESSAGE
|
30
|
+
|
31
|
+
#{'*'*50}
|
87
32
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
trap("SIGHUP"){ restart_test_server }
|
96
|
-
File.open("/dev/null"){|f|
|
97
|
-
STDERR.reopen f
|
98
|
-
STDIN.reopen f
|
99
|
-
STDOUT.reopen f
|
100
|
-
}
|
101
|
-
yield
|
102
|
-
}
|
103
|
-
puts "spec_server launched. (PID: %d)" % pid
|
104
|
-
File.open(pid_file,"w"){|f| f.puts pid } if pid_file
|
105
|
-
exit! 0
|
33
|
+
spec_server won't reload your classes if config.cache_classes
|
34
|
+
is set to true. Please modify environment/test.rb:
|
35
|
+
|
36
|
+
config.cache_classes = false
|
37
|
+
|
38
|
+
#{'*'*50}
|
39
|
+
MESSAGE
|
106
40
|
end
|
107
41
|
|
108
42
|
options = Hash.new
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
puts "Ready"
|
115
|
-
exec_server = lambda {
|
116
|
-
trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
|
117
|
-
DRb.start_service("druby://127.0.0.1:8989", Spec::Runner::RailsSpecServer.new)
|
118
|
-
DRb.thread.join
|
119
|
-
}
|
43
|
+
parser = OptionParser.new
|
44
|
+
parser.on("-d", "--daemon") {|ignore| options[:daemon] = true }
|
45
|
+
parser.on("-p", "--pid PIDFILE"){|pid| options[:pid] = pid }
|
46
|
+
parser.parse!(ARGV)
|
120
47
|
|
121
48
|
if options[:daemon]
|
122
|
-
daemonize(options[:pid]
|
49
|
+
::Spec::Rails::SpecServer.daemonize(options[:pid])
|
123
50
|
else
|
124
|
-
|
51
|
+
::Spec::Rails::SpecServer.run
|
125
52
|
end
|
@@ -15,11 +15,7 @@ class RspecControllerGenerator < ControllerGenerator
|
|
15
15
|
m.directory File.join('spec/helpers', class_path)
|
16
16
|
m.directory File.join('spec/views', class_path, file_name)
|
17
17
|
|
18
|
-
|
19
|
-
@default_file_extension = "rhtml"
|
20
|
-
else
|
21
|
-
@default_file_extension = "html.erb"
|
22
|
-
end
|
18
|
+
@default_file_extension = "html.erb"
|
23
19
|
|
24
20
|
# Controller spec, class, and helper.
|
25
21
|
m.template 'controller_spec.rb',
|
@@ -30,19 +30,7 @@ class RspecScaffoldGenerator < Rails::Generator::NamedBase
|
|
30
30
|
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
@resource_generator = "scaffold_resource"
|
35
|
-
@default_file_extension = "rhtml"
|
36
|
-
else
|
37
|
-
@resource_generator = "scaffold"
|
38
|
-
@default_file_extension = "html.erb"
|
39
|
-
end
|
40
|
-
|
41
|
-
if ActionController::Base.respond_to?(:resource_action_separator)
|
42
|
-
@resource_edit_path = "/edit"
|
43
|
-
else
|
44
|
-
@resource_edit_path = ";edit"
|
45
|
-
end
|
33
|
+
@default_file_extension = "html.erb"
|
46
34
|
end
|
47
35
|
|
48
36
|
def manifest
|
@@ -57,31 +45,39 @@ class RspecScaffoldGenerator < Rails::Generator::NamedBase
|
|
57
45
|
m.directory(File.join('app/controllers', controller_class_path))
|
58
46
|
m.directory(File.join('app/helpers', controller_class_path))
|
59
47
|
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
48
|
+
m.directory(File.join('app/views/layouts', controller_class_path))
|
49
|
+
m.directory(File.join('public/stylesheets', class_path))
|
50
|
+
|
60
51
|
m.directory(File.join('spec/controllers', controller_class_path))
|
52
|
+
m.directory(File.join('spec/routing', controller_class_path))
|
61
53
|
m.directory(File.join('spec/models', class_path))
|
62
54
|
m.directory(File.join('spec/helpers', class_path))
|
63
55
|
m.directory File.join('spec/fixtures', class_path)
|
64
56
|
m.directory File.join('spec/views', controller_class_path, controller_file_name)
|
65
57
|
|
58
|
+
# Layout and stylesheet.
|
59
|
+
m.template("scaffold:layout.html.erb", File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
|
60
|
+
m.template("scaffold:style.css", 'public/stylesheets/scaffold.css')
|
61
|
+
|
66
62
|
# Controller spec, class, and helper.
|
67
63
|
m.template 'rspec_scaffold:routing_spec.rb',
|
68
|
-
File.join('spec/
|
64
|
+
File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
|
69
65
|
|
70
66
|
m.template 'rspec_scaffold:controller_spec.rb',
|
71
67
|
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
72
68
|
|
73
|
-
m.template "
|
69
|
+
m.template "scaffold:controller.rb",
|
74
70
|
File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
75
71
|
|
76
72
|
m.template 'rspec_scaffold:helper_spec.rb',
|
77
73
|
File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
|
78
74
|
|
79
|
-
m.template "
|
75
|
+
m.template "scaffold:helper.rb",
|
80
76
|
File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")
|
81
77
|
|
82
78
|
for action in scaffold_views
|
83
79
|
m.template(
|
84
|
-
"
|
80
|
+
"scaffold:view_#{action}.#{@default_file_extension}",
|
85
81
|
File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
|
86
82
|
)
|
87
83
|
end
|
@@ -6,9 +6,9 @@ describe <%= controller_class_name %>Controller do
|
|
6
6
|
@mock_<%= file_name %> ||= mock_model(<%= class_name %>, stubs)
|
7
7
|
end
|
8
8
|
|
9
|
-
describe "
|
9
|
+
describe "GET index" do
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "exposes all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
12
12
|
<%= class_name %>.should_receive(:find).with(:all).and_return([mock_<%= file_name %>])
|
13
13
|
get :index
|
14
14
|
assigns[:<%= table_name %>].should == [mock_<%= file_name %>]
|
@@ -16,11 +16,10 @@ describe <%= controller_class_name %>Controller do
|
|
16
16
|
|
17
17
|
describe "with mime type of xml" do
|
18
18
|
|
19
|
-
it "
|
20
|
-
request.env["HTTP_ACCEPT"] = "application/xml"
|
19
|
+
it "renders all <%= table_name.pluralize %> as xml" do
|
21
20
|
<%= class_name %>.should_receive(:find).with(:all).and_return(<%= file_name.pluralize %> = mock("Array of <%= class_name.pluralize %>"))
|
22
21
|
<%= file_name.pluralize %>.should_receive(:to_xml).and_return("generated XML")
|
23
|
-
get :index
|
22
|
+
get :index, :format => 'xml'
|
24
23
|
response.body.should == "generated XML"
|
25
24
|
end
|
26
25
|
|
@@ -28,9 +27,9 @@ describe <%= controller_class_name %>Controller do
|
|
28
27
|
|
29
28
|
end
|
30
29
|
|
31
|
-
describe "
|
30
|
+
describe "GET show" do
|
32
31
|
|
33
|
-
it "
|
32
|
+
it "exposes the requested <%= file_name %> as @<%= file_name %>" do
|
34
33
|
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
35
34
|
get :show, :id => "37"
|
36
35
|
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
|
@@ -38,11 +37,10 @@ describe <%= controller_class_name %>Controller do
|
|
38
37
|
|
39
38
|
describe "with mime type of xml" do
|
40
39
|
|
41
|
-
it "
|
42
|
-
request.env["HTTP_ACCEPT"] = "application/xml"
|
40
|
+
it "renders the requested <%= file_name %> as xml" do
|
43
41
|
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
44
42
|
mock_<%= file_name %>.should_receive(:to_xml).and_return("generated XML")
|
45
|
-
get :show, :id => "37"
|
43
|
+
get :show, :id => "37", :format => 'xml'
|
46
44
|
response.body.should == "generated XML"
|
47
45
|
end
|
48
46
|
|
@@ -50,9 +48,9 @@ describe <%= controller_class_name %>Controller do
|
|
50
48
|
|
51
49
|
end
|
52
50
|
|
53
|
-
describe "
|
51
|
+
describe "GET new" do
|
54
52
|
|
55
|
-
it "
|
53
|
+
it "exposes a new <%= file_name %> as @<%= file_name %>" do
|
56
54
|
<%= class_name %>.should_receive(:new).and_return(mock_<%= file_name %>)
|
57
55
|
get :new
|
58
56
|
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
|
@@ -60,9 +58,9 @@ describe <%= controller_class_name %>Controller do
|
|
60
58
|
|
61
59
|
end
|
62
60
|
|
63
|
-
describe "
|
61
|
+
describe "GET edit" do
|
64
62
|
|
65
|
-
it "
|
63
|
+
it "exposes the requested <%= file_name %> as @<%= file_name %>" do
|
66
64
|
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
67
65
|
get :edit, :id => "37"
|
68
66
|
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
|
@@ -70,17 +68,17 @@ describe <%= controller_class_name %>Controller do
|
|
70
68
|
|
71
69
|
end
|
72
70
|
|
73
|
-
describe "
|
71
|
+
describe "POST create" do
|
74
72
|
|
75
73
|
describe "with valid params" do
|
76
74
|
|
77
|
-
it "
|
75
|
+
it "exposes a newly created <%= file_name %> as @<%= file_name %>" do
|
78
76
|
<%= class_name %>.should_receive(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
|
79
77
|
post :create, :<%= file_name %> => {:these => 'params'}
|
80
78
|
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
81
79
|
end
|
82
80
|
|
83
|
-
it "
|
81
|
+
it "redirects to the created <%= file_name %>" do
|
84
82
|
<%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => true))
|
85
83
|
post :create, :<%= file_name %> => {}
|
86
84
|
response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
|
@@ -90,13 +88,13 @@ describe <%= controller_class_name %>Controller do
|
|
90
88
|
|
91
89
|
describe "with invalid params" do
|
92
90
|
|
93
|
-
it "
|
91
|
+
it "exposes a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
|
94
92
|
<%= class_name %>.stub!(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
|
95
93
|
post :create, :<%= file_name %> => {:these => 'params'}
|
96
94
|
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
97
95
|
end
|
98
96
|
|
99
|
-
it "
|
97
|
+
it "re-renders the 'new' template" do
|
100
98
|
<%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => false))
|
101
99
|
post :create, :<%= file_name %> => {}
|
102
100
|
response.should render_template('new')
|
@@ -106,23 +104,23 @@ describe <%= controller_class_name %>Controller do
|
|
106
104
|
|
107
105
|
end
|
108
106
|
|
109
|
-
describe "
|
107
|
+
describe "PUT udpate" do
|
110
108
|
|
111
109
|
describe "with valid params" do
|
112
110
|
|
113
|
-
it "
|
111
|
+
it "updates the requested <%= file_name %>" do
|
114
112
|
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
115
113
|
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
|
116
114
|
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
|
117
115
|
end
|
118
116
|
|
119
|
-
it "
|
117
|
+
it "exposes the requested <%= file_name %> as @<%= file_name %>" do
|
120
118
|
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
|
121
119
|
put :update, :id => "1"
|
122
120
|
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
123
121
|
end
|
124
122
|
|
125
|
-
it "
|
123
|
+
it "redirects to the <%= file_name %>" do
|
126
124
|
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
|
127
125
|
put :update, :id => "1"
|
128
126
|
response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
|
@@ -132,19 +130,19 @@ describe <%= controller_class_name %>Controller do
|
|
132
130
|
|
133
131
|
describe "with invalid params" do
|
134
132
|
|
135
|
-
it "
|
133
|
+
it "updates the requested <%= file_name %>" do
|
136
134
|
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
137
135
|
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
|
138
136
|
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
|
139
137
|
end
|
140
138
|
|
141
|
-
it "
|
139
|
+
it "exposes the <%= file_name %> as @<%= file_name %>" do
|
142
140
|
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
|
143
141
|
put :update, :id => "1"
|
144
142
|
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
145
143
|
end
|
146
144
|
|
147
|
-
it "
|
145
|
+
it "re-renders the 'edit' template" do
|
148
146
|
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
|
149
147
|
put :update, :id => "1"
|
150
148
|
response.should render_template('edit')
|
@@ -154,15 +152,15 @@ describe <%= controller_class_name %>Controller do
|
|
154
152
|
|
155
153
|
end
|
156
154
|
|
157
|
-
describe "
|
155
|
+
describe "DELETE destroy" do
|
158
156
|
|
159
|
-
it "
|
157
|
+
it "destroys the requested <%= file_name %>" do
|
160
158
|
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
161
159
|
mock_<%= file_name %>.should_receive(:destroy)
|
162
160
|
delete :destroy, :id => "37"
|
163
161
|
end
|
164
162
|
|
165
|
-
it "
|
163
|
+
it "redirects to the <%= table_name %> list" do
|
166
164
|
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:destroy => true))
|
167
165
|
delete :destroy, :id => "1"
|
168
166
|
response.should redirect_to(<%= table_name %>_url)
|