rspec-rails 1.3.4 → 2.0.0.a2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -7
- data/README.markdown +58 -0
- data/Rakefile +51 -9
- data/example_app_template.rb +33 -0
- data/lib/generators/rspec.rb +25 -0
- data/lib/generators/rspec/controller/controller_generator.rb +26 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +15 -0
- data/lib/generators/rspec/controller/templates/view_spec.rb +12 -0
- data/lib/generators/rspec/helper/helper_generator.rb +11 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +14 -0
- data/lib/generators/rspec/install/install_generator.rb +29 -0
- data/lib/generators/rspec/install/templates/lib/tasks/rspec.rake +119 -0
- data/lib/generators/rspec/install/templates/script/rspec.tt +4 -0
- data/{generators/rspec/templates → lib/generators/rspec/install/templates/spec}/rcov.opts +0 -0
- data/{generators/rspec/templates → lib/generators/rspec/install/templates/spec}/spec.opts +0 -0
- data/{generators/rspec/templates → lib/generators/rspec/install/templates/spec}/spec_helper.rb +14 -12
- data/lib/generators/rspec/integration/integration_generator.rb +12 -0
- data/{generators/integration_spec/templates/integration_spec.rb → lib/generators/rspec/integration/templates/request_spec.rb} +0 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +21 -0
- data/lib/generators/rspec/mailer/templates/fixture +3 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +14 -0
- data/lib/generators/rspec/model/model_generator.rb +22 -0
- data/lib/generators/rspec/model/templates/fixtures.yml +19 -0
- data/{generators/rspec_model → lib/generators/rspec/model}/templates/model_spec.rb +1 -1
- data/lib/generators/rspec/observer/observer_generator.rb +12 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +5 -0
- data/lib/generators/rspec/plugin/plugin_generator.rb +11 -0
- data/lib/generators/rspec/plugin/templates/%file_name%_spec.rb.tt +5 -0
- data/lib/generators/rspec/plugin/templates/test_helper.rb +5 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +112 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +127 -0
- data/{generators/rspec_scaffold/templates/edit_erb_spec.rb → lib/generators/rspec/scaffold/templates/edit_spec.rb} +3 -3
- data/{generators/rspec_scaffold/templates/index_erb_spec.rb → lib/generators/rspec/scaffold/templates/index_spec.rb} +4 -4
- data/{generators/rspec_scaffold/templates/new_erb_spec.rb → lib/generators/rspec/scaffold/templates/new_spec.rb} +3 -3
- data/{generators/rspec_scaffold → lib/generators/rspec/scaffold}/templates/routing_spec.rb +4 -0
- data/{generators/rspec_scaffold/templates/show_erb_spec.rb → lib/generators/rspec/scaffold/templates/show_spec.rb} +4 -4
- data/lib/rspec/rails.rb +2 -0
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/example/controller_example_group.rb +31 -0
- data/lib/rspec/rails/example/request_example_group.rb +26 -0
- data/lib/rspec/rails/matchers.rb +14 -0
- data/lib/rspec/rails/transactional_database_support.rb +38 -0
- data/lib/rspec/rails/version.rb +16 -0
- data/rspec-rails.gemspec +78 -18
- metadata +97 -321
- data/.document +0 -7
- data/Contribute.rdoc +0 -4
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -27
- data/History.rdoc +0 -321
- data/License.txt +0 -33
- data/Manifest.txt +0 -165
- data/README.rdoc +0 -48
- data/TODO.txt +0 -17
- data/Upgrade.rdoc +0 -148
- data/generators/integration_spec/integration_spec_generator.rb +0 -10
- data/generators/rspec/CHANGES +0 -1
- data/generators/rspec/rspec_generator.rb +0 -72
- data/generators/rspec/templates/previous_failures.txt +0 -0
- data/generators/rspec/templates/rspec.rake +0 -144
- data/generators/rspec/templates/script/autospec +0 -6
- data/generators/rspec/templates/script/spec +0 -10
- data/generators/rspec_controller/USAGE +0 -33
- data/generators/rspec_controller/rspec_controller_generator.rb +0 -47
- data/generators/rspec_controller/templates/controller_spec.rb +0 -25
- data/generators/rspec_controller/templates/helper_spec.rb +0 -11
- data/generators/rspec_controller/templates/view_spec.rb +0 -12
- data/generators/rspec_default_values.rb +0 -28
- data/generators/rspec_model/USAGE +0 -18
- data/generators/rspec_model/rspec_model_generator.rb +0 -35
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +0 -154
- data/generators/rspec_scaffold/templates/controller_spec.rb +0 -131
- data/generators/rspec_scaffold/templates/helper_spec.rb +0 -11
- data/init.rb +0 -9
- data/lib/autotest/discover.rb +0 -5
- data/lib/autotest/rails_rspec.rb +0 -76
- data/lib/spec/rails.rb +0 -26
- data/lib/spec/rails/example.rb +0 -48
- data/lib/spec/rails/example/assigns_hash_proxy.rb +0 -39
- data/lib/spec/rails/example/controller_example_group.rb +0 -285
- data/lib/spec/rails/example/cookies_proxy.rb +0 -29
- data/lib/spec/rails/example/functional_example_group.rb +0 -106
- data/lib/spec/rails/example/helper_example_group.rb +0 -153
- data/lib/spec/rails/example/integration_example_group.rb +0 -16
- data/lib/spec/rails/example/model_example_group.rb +0 -15
- data/lib/spec/rails/example/render_observer.rb +0 -80
- data/lib/spec/rails/example/routing_example_group.rb +0 -16
- data/lib/spec/rails/example/routing_helpers.rb +0 -66
- data/lib/spec/rails/example/view_example_group.rb +0 -203
- data/lib/spec/rails/extensions.rb +0 -11
- data/lib/spec/rails/extensions/action_controller/rescue.rb +0 -42
- data/lib/spec/rails/extensions/action_controller/test_case.rb +0 -16
- data/lib/spec/rails/extensions/action_controller/test_response.rb +0 -21
- data/lib/spec/rails/extensions/action_view/base.rb +0 -35
- data/lib/spec/rails/extensions/active_record/base.rb +0 -45
- data/lib/spec/rails/extensions/active_support/test_case.rb +0 -7
- data/lib/spec/rails/extensions/spec/matchers/have.rb +0 -23
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +0 -45
- data/lib/spec/rails/interop/testcase.rb +0 -14
- data/lib/spec/rails/matchers.rb +0 -32
- data/lib/spec/rails/matchers/ar_be_valid.rb +0 -27
- data/lib/spec/rails/matchers/assert_select.rb +0 -180
- data/lib/spec/rails/matchers/change.rb +0 -13
- data/lib/spec/rails/matchers/have_text.rb +0 -57
- data/lib/spec/rails/matchers/include_text.rb +0 -54
- data/lib/spec/rails/matchers/redirect_to.rb +0 -126
- data/lib/spec/rails/matchers/render_template.rb +0 -129
- data/lib/spec/rails/matchers/route_to.rb +0 -149
- data/lib/spec/rails/mocks.rb +0 -140
- data/lib/spec/rails/version.rb +0 -16
- data/spec/autotest/mappings_spec.rb +0 -86
- data/spec/rails_suite.rb +0 -7
- data/spec/resources/controllers/action_view_base_spec_controller.rb +0 -2
- data/spec/resources/controllers/application.rb +0 -9
- data/spec/resources/controllers/controller_spec_controller.rb +0 -127
- data/spec/resources/controllers/example.txt +0 -1
- data/spec/resources/controllers/redirect_spec_controller.rb +0 -70
- data/spec/resources/controllers/render_spec_controller.rb +0 -34
- data/spec/resources/controllers/rjs_spec_controller.rb +0 -58
- data/spec/resources/helpers/addition_helper.rb +0 -5
- data/spec/resources/helpers/explicit_helper.rb +0 -46
- data/spec/resources/helpers/more_explicit_helper.rb +0 -5
- data/spec/resources/helpers/plugin_application_helper.rb +0 -6
- data/spec/resources/helpers/view_spec_helper.rb +0 -13
- data/spec/resources/models/animal.rb +0 -4
- data/spec/resources/models/person.rb +0 -18
- data/spec/resources/models/thing.rb +0 -3
- data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
- data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +0 -1
- data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +0 -1
- data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
- data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +0 -1
- data/spec/resources/views/controller_spec/action_with_template.html.erb +0 -1
- data/spec/resources/views/controller_spec/non_existent_action_with_existent_template.html.erb +0 -1
- data/spec/resources/views/layouts/application.html.erb +0 -0
- data/spec/resources/views/layouts/simple.html.erb +0 -0
- data/spec/resources/views/objects/_object.html.erb +0 -1
- data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
- data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
- data/spec/resources/views/render_spec/some_action.html.erb +0 -0
- data/spec/resources/views/render_spec/some_action.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +0 -1
- data/spec/resources/views/rjs_spec/hide_div.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/insert_html.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/replace.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/replace_html.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/visual_effect.js.rjs +0 -1
- data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +0 -1
- data/spec/resources/views/tag_spec/no_tags.html.erb +0 -1
- data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +0 -1
- data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +0 -1
- data/spec/resources/views/view_spec/_partial.html.erb +0 -2
- data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
- data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +0 -1
- data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +0 -1
- data/spec/resources/views/view_spec/_spacer.html.erb +0 -1
- data/spec/resources/views/view_spec/accessor.html.erb +0 -6
- data/spec/resources/views/view_spec/block_helper.html.erb +0 -3
- data/spec/resources/views/view_spec/entry_form.html.erb +0 -2
- data/spec/resources/views/view_spec/explicit_helper.html.erb +0 -2
- data/spec/resources/views/view_spec/foo/show.html.erb +0 -1
- data/spec/resources/views/view_spec/implicit_helper.html.erb +0 -2
- data/spec/resources/views/view_spec/multiple_helpers.html.erb +0 -3
- data/spec/resources/views/view_spec/path_params.html.erb +0 -1
- data/spec/resources/views/view_spec/should_not_receive.html.erb +0 -3
- data/spec/resources/views/view_spec/template_with_partial.html.erb +0 -5
- data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +0 -3
- data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +0 -1
- data/spec/resources/views/view_spec/view_helpers.html.erb +0 -1
- data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +0 -109
- data/spec/spec/rails/example/configuration_spec.rb +0 -67
- data/spec/spec/rails/example/controller_example_group_spec.rb +0 -307
- data/spec/spec/rails/example/controller_isolation_spec.rb +0 -75
- data/spec/spec/rails/example/cookies_proxy_spec.rb +0 -87
- data/spec/spec/rails/example/error_handling_spec.rb +0 -90
- data/spec/spec/rails/example/example_group_factory_spec.rb +0 -112
- data/spec/spec/rails/example/helper_example_group_spec.rb +0 -247
- data/spec/spec/rails/example/model_example_group_spec.rb +0 -32
- data/spec/spec/rails/example/routing_example_group_spec.rb +0 -9
- data/spec/spec/rails/example/shared_routing_example_group_examples.rb +0 -237
- data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +0 -33
- data/spec/spec/rails/example/view_example_group_spec.rb +0 -346
- data/spec/spec/rails/extensions/action_view_base_spec.rb +0 -79
- data/spec/spec/rails/extensions/active_record_spec.rb +0 -14
- data/spec/spec/rails/interop/testcase_spec.rb +0 -70
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +0 -19
- data/spec/spec/rails/matchers/assert_select_spec.rb +0 -835
- data/spec/spec/rails/matchers/errors_on_spec.rb +0 -37
- data/spec/spec/rails/matchers/have_text_spec.rb +0 -69
- data/spec/spec/rails/matchers/include_text_spec.rb +0 -62
- data/spec/spec/rails/matchers/redirect_to_spec.rb +0 -253
- data/spec/spec/rails/matchers/render_template_spec.rb +0 -208
- data/spec/spec/rails/matchers/should_change_spec.rb +0 -15
- data/spec/spec/rails/mocks/ar_classes.rb +0 -10
- data/spec/spec/rails/mocks/mock_model_spec.rb +0 -112
- data/spec/spec/rails/mocks/stub_model_spec.rb +0 -80
- data/spec/spec/rails/sample_modified_fixture.rb +0 -8
- data/spec/spec/rails/sample_spec.rb +0 -8
- data/spec/spec/rails/spec_spec.rb +0 -11
- data/spec/spec_helper.rb +0 -78
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class MailerGenerator < Base
|
6
|
+
argument :actions, :type => :array, :default => [], :banner => "method method"
|
7
|
+
|
8
|
+
def create_mailer_files
|
9
|
+
template "mailer_spec.rb",
|
10
|
+
File.join('spec', 'models', class_path, "#{file_name}_spec.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_fixtures_files
|
14
|
+
actions.each do |action|
|
15
|
+
@action, @path = action, File.join(file_path, action)
|
16
|
+
template "fixture", File.join("spec/fixtures", @path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe <%= class_name %> do
|
4
|
+
<% for action in actions -%>
|
5
|
+
it "should deliver <%= action.gsub("_", " ") %> message" do
|
6
|
+
@expected.subject = '<%= class_name %>#<%= action %>'
|
7
|
+
@expected.body = read_fixture('<%= action %>')
|
8
|
+
@expected.date = Time.now
|
9
|
+
|
10
|
+
@expected.encoded.should == <%= class_name %>.create_<%= action %>(@expected.date).encoded
|
11
|
+
end
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
class_option :fixture, :type => :boolean
|
8
|
+
|
9
|
+
def create_test_file
|
10
|
+
template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
hook_for :fixture_replacement
|
14
|
+
|
15
|
+
def create_fixture_file
|
16
|
+
if options[:fixture] && options[:fixture_replacement].nil?
|
17
|
+
template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
|
3
|
+
<% unless attributes.empty? -%>
|
4
|
+
one:
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
<%= attribute.name %>: <%= attribute.default %>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
two:
|
10
|
+
<% for attribute in attributes -%>
|
11
|
+
<%= attribute.name %>: <%= attribute.default %>
|
12
|
+
<% end -%>
|
13
|
+
<% else -%>
|
14
|
+
# one:
|
15
|
+
# column: value
|
16
|
+
#
|
17
|
+
# two:
|
18
|
+
# column: value
|
19
|
+
<% end -%>
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe <%= class_name %> do
|
4
4
|
before(:each) do
|
5
5
|
@valid_attributes = {
|
6
|
-
<%= attributes.map{|a| ":#{a.
|
6
|
+
<%= attributes.map{ |a| ":#{a.name} => #{a.default.inspect}" }.join(",\n ") %>
|
7
7
|
}
|
8
8
|
end
|
9
9
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class ObserverGenerator < Base
|
6
|
+
def create_observer_files
|
7
|
+
template 'observer_spec.rb',
|
8
|
+
File.join('spec', 'models', class_path, "#{file_name}_observer_spec.rb")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
require 'generators/resource_helpers'
|
3
|
+
|
4
|
+
module Rspec
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Base
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
9
|
+
|
10
|
+
class_option :orm, :desc => "ORM used to generate the controller"
|
11
|
+
class_option :template_engine, :desc => "Template engine to generate view files"
|
12
|
+
class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
|
13
|
+
|
14
|
+
class_option :views, :type => :boolean, :default => true
|
15
|
+
class_option :routes, :type => :boolean, :default => true
|
16
|
+
|
17
|
+
def copy_controller_files
|
18
|
+
template 'controller_spec.rb',
|
19
|
+
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy_view_files
|
23
|
+
return unless options[:views]
|
24
|
+
|
25
|
+
copy_view :edit
|
26
|
+
copy_view :index unless options[:singleton]
|
27
|
+
copy_view :new
|
28
|
+
copy_view :show
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_routing_files
|
32
|
+
return unless options[:routes]
|
33
|
+
|
34
|
+
template 'routing_spec.rb',
|
35
|
+
File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
|
36
|
+
end
|
37
|
+
|
38
|
+
hook_for :integration_tool, :as => :integration
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def copy_view(view)
|
43
|
+
template "#{view}_spec.rb",
|
44
|
+
File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
45
|
+
end
|
46
|
+
|
47
|
+
def params
|
48
|
+
"{'these' => 'params'}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the name of the mock. For example, if the file name is user,
|
52
|
+
# it returns mock_user.
|
53
|
+
#
|
54
|
+
# If a hash is given, it uses the hash key as the ORM method and the
|
55
|
+
# value as response. So, for ActiveRecord and file name "User":
|
56
|
+
#
|
57
|
+
# mock_file_name(:save => true)
|
58
|
+
# #=> mock_user(:save => true)
|
59
|
+
#
|
60
|
+
# If another ORM is being used and another method instead of save is
|
61
|
+
# called, it will be the one used.
|
62
|
+
#
|
63
|
+
def mock_file_name(hash=nil)
|
64
|
+
if hash
|
65
|
+
method, and_return = hash.to_a.first
|
66
|
+
method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
|
67
|
+
"mock_#{file_name}(:#{method} => #{and_return})"
|
68
|
+
else
|
69
|
+
"mock_#{file_name}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Receives the ORM chain and convert to expects. For ActiveRecord:
|
74
|
+
#
|
75
|
+
# should! orm_class.find(User, "37")
|
76
|
+
# #=> User.should_receive(:find).with(37)
|
77
|
+
#
|
78
|
+
# For Datamapper:
|
79
|
+
#
|
80
|
+
# should! orm_class.find(User, "37")
|
81
|
+
# #=> User.should_receive(:get).with(37)
|
82
|
+
#
|
83
|
+
def should!(chain)
|
84
|
+
stub_or_should_chain(:should_receive, chain)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Receives the ORM chain and convert to stub. For ActiveRecord:
|
88
|
+
#
|
89
|
+
# stub! orm_class.find(User, "37")
|
90
|
+
# #=> User.stub!(:find).with(37)
|
91
|
+
#
|
92
|
+
# For Datamapper:
|
93
|
+
#
|
94
|
+
# stub! orm_class.find(User, "37")
|
95
|
+
# #=> User.stub!(:get).with(37)
|
96
|
+
#
|
97
|
+
def stub!(chain)
|
98
|
+
stub_or_should_chain(:stub!, chain)
|
99
|
+
end
|
100
|
+
|
101
|
+
def stub_or_should_chain(mode, chain)
|
102
|
+
receiver, method = chain.split(".")
|
103
|
+
method.gsub!(/\((.*?)\)/, '')
|
104
|
+
|
105
|
+
response = "#{receiver}.#{mode}(:#{method})"
|
106
|
+
response << ".with(#{$1})" unless $1.blank?
|
107
|
+
response
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe <%= controller_class_name %>Controller do
|
4
|
+
|
5
|
+
def <%= mock_file_name %>(stubs={})
|
6
|
+
@<%= mock_file_name %> ||= mock_model(<%= class_name %>, stubs)
|
7
|
+
end
|
8
|
+
|
9
|
+
<% unless options[:singleton] -%>
|
10
|
+
describe "GET index" do
|
11
|
+
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
12
|
+
<%= stub! orm_class.all(class_name) %>.and_return([<%= mock_file_name %>])
|
13
|
+
get :index
|
14
|
+
assigns[:<%= table_name %>].should == [<%= mock_file_name %>]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
<% end -%>
|
18
|
+
|
19
|
+
describe "GET show" do
|
20
|
+
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
|
21
|
+
<%= stub! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
22
|
+
get :show, :id => "37"
|
23
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "GET new" do
|
28
|
+
it "assigns a new <%= file_name %> as @<%= file_name %>" do
|
29
|
+
<%= stub! orm_class.build(class_name) %>.and_return(<%= mock_file_name %>)
|
30
|
+
get :new
|
31
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "GET edit" do
|
36
|
+
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
|
37
|
+
<%= stub! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
38
|
+
get :edit, :id => "37"
|
39
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "POST create" do
|
44
|
+
|
45
|
+
describe "with valid params" do
|
46
|
+
it "assigns a newly created <%= file_name %> as @<%= file_name %>" do
|
47
|
+
<%= stub! orm_class.build(class_name, params) %>.and_return(<%= mock_file_name(:save => true) %>)
|
48
|
+
post :create, :<%= file_name %> => <%= params %>
|
49
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "redirects to the created <%= file_name %>" do
|
53
|
+
<%= stub! orm_class.build(class_name) %>.and_return(<%= mock_file_name(:save => true) %>)
|
54
|
+
post :create, :<%= file_name %> => {}
|
55
|
+
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "with invalid params" do
|
60
|
+
it "assigns a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
|
61
|
+
<%= stub! orm_class.build(class_name, params) %>.and_return(<%= mock_file_name(:save => false) %>)
|
62
|
+
post :create, :<%= file_name %> => <%= params %>
|
63
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "re-renders the 'new' template" do
|
67
|
+
<%= stub! orm_class.build(class_name) %>.and_return(<%= mock_file_name(:save => false) %>)
|
68
|
+
post :create, :<%= file_name %> => {}
|
69
|
+
response.should render_template('new')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "PUT update" do
|
76
|
+
|
77
|
+
describe "with valid params" do
|
78
|
+
it "updates the requested <%= file_name %>" do
|
79
|
+
<%= should! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
80
|
+
mock_<%= should! orm_instance.update_attributes(params) %>
|
81
|
+
put :update, :id => "37", :<%= file_name %> => <%= params %>
|
82
|
+
end
|
83
|
+
|
84
|
+
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
|
85
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => true) %>)
|
86
|
+
put :update, :id => "1"
|
87
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "redirects to the <%= file_name %>" do
|
91
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => true) %>)
|
92
|
+
put :update, :id => "1"
|
93
|
+
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "with invalid params" do
|
98
|
+
it "assigns the <%= file_name %> as @<%= file_name %>" do
|
99
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => false) %>)
|
100
|
+
put :update, :id => "1"
|
101
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "re-renders the 'edit' template" do
|
105
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => false) %>)
|
106
|
+
put :update, :id => "1"
|
107
|
+
response.should render_template('edit')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "DELETE destroy" do
|
114
|
+
it "destroys the requested <%= file_name %>" do
|
115
|
+
<%= should! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
116
|
+
mock_<%= should! orm_instance.destroy %>
|
117
|
+
delete :destroy, :id => "37"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "redirects to the <%= table_name %> list" do
|
121
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:destroy => true) %>)
|
122
|
+
delete :destroy, :id => "1"
|
123
|
+
response.should redirect_to(<%= table_name %>_url)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "/<%= table_name %>/edit.<%=
|
4
|
+
describe "/<%= table_name %>/edit.html.<%= options[:template_engine] %>" do
|
5
5
|
include <%= controller_class_name %>Helper
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
|
9
9
|
:new_record? => false<%= output_attributes.empty? ? '' : ',' %>
|
10
10
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
11
|
-
:<%= attribute.name %> => <%= attribute.
|
11
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
12
12
|
<% end -%>
|
13
13
|
)
|
14
14
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "/<%= table_name %>/index.<%=
|
4
|
+
describe "/<%= table_name %>/index.html.<%= options[:template_engine] %>" do
|
5
5
|
include <%= controller_class_name %>Helper
|
6
6
|
|
7
7
|
before(:each) do
|
@@ -9,7 +9,7 @@ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
|
|
9
9
|
<% [1,2].each_with_index do |id, model_index| -%>
|
10
10
|
stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
|
11
11
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
12
|
-
:<%= attribute.name %> => <%= attribute.
|
12
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
13
13
|
<% end -%>
|
14
14
|
<% if !output_attributes.empty? -%>
|
15
15
|
<%= model_index == 1 ? ')' : '),' %>
|
@@ -21,7 +21,7 @@ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
|
|
21
21
|
it "renders a list of <%= table_name %>" do
|
22
22
|
render
|
23
23
|
<% for attribute in output_attributes -%>
|
24
|
-
response.should have_tag("tr>td", <%= attribute.
|
24
|
+
response.should have_tag("tr>td", <%= attribute.default.inspect %>.to_s, 2)
|
25
25
|
<% end -%>
|
26
26
|
end
|
27
27
|
end
|