francois-shoulda 2.0.5.4 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +60 -10
- data/Rakefile +7 -7
- data/lib/shoulda.rb +7 -15
- data/lib/shoulda/action_controller.rb +28 -0
- data/lib/shoulda/action_controller/helpers.rb +47 -0
- data/lib/shoulda/action_controller/macros.rb +277 -0
- data/lib/shoulda/action_controller/matchers.rb +37 -0
- data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
- data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
- data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
- data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
- data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +81 -0
- data/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
- data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +87 -0
- data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
- data/lib/shoulda/action_mailer.rb +1 -1
- data/lib/shoulda/action_mailer/assertions.rb +32 -33
- data/lib/shoulda/action_view.rb +10 -0
- data/lib/shoulda/action_view/macros.rb +56 -0
- data/lib/shoulda/active_record.rb +6 -2
- data/lib/shoulda/active_record/assertions.rb +62 -89
- data/lib/shoulda/active_record/helpers.rb +40 -0
- data/lib/shoulda/active_record/macros.rb +520 -684
- data/lib/shoulda/active_record/matchers.rb +42 -0
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
- data/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
- data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
- data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
- data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
- data/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
- data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
- data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
- data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
- data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
- data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
- data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
- data/lib/shoulda/assertions.rb +50 -40
- data/lib/shoulda/autoload_macros.rb +46 -0
- data/lib/shoulda/context.rb +124 -126
- data/lib/shoulda/helpers.rb +5 -7
- data/lib/shoulda/macros.rb +63 -64
- data/lib/shoulda/private_helpers.rb +16 -18
- data/lib/shoulda/rails.rb +5 -11
- data/lib/shoulda/rspec.rb +11 -0
- data/lib/shoulda/tasks/list_tests.rake +6 -1
- data/lib/shoulda/test_unit.rb +19 -0
- data/rails/init.rb +7 -1
- data/test/README +2 -2
- data/test/fail_macros.rb +15 -15
- data/test/fixtures/tags.yml +1 -1
- data/test/functional/posts_controller_test.rb +46 -26
- data/test/functional/users_controller_test.rb +0 -19
- data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +68 -0
- data/test/matchers/active_record/allow_value_matcher_test.rb +41 -0
- data/test/matchers/active_record/association_matcher_test.rb +258 -0
- data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +80 -0
- data/test/matchers/active_record/ensure_length_of_matcher_test.rb +158 -0
- data/test/matchers/active_record/have_db_column_matcher_test.rb +169 -0
- data/test/matchers/active_record/have_index_matcher_test.rb +74 -0
- data/test/matchers/active_record/have_named_scope_matcher_test.rb +65 -0
- data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +29 -0
- data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +44 -0
- data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +52 -0
- data/test/matchers/active_record/validate_presence_of_matcher_test.rb +86 -0
- data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +147 -0
- data/test/matchers/controller/assign_to_matcher_test.rb +35 -0
- data/test/matchers/controller/filter_param_matcher_test.rb +32 -0
- data/test/matchers/controller/render_with_layout_matcher_test.rb +33 -0
- data/test/matchers/controller/respond_with_content_type_matcher_test.rb +27 -0
- data/test/matchers/controller/respond_with_matcher_test.rb +106 -0
- data/test/matchers/controller/route_matcher_test.rb +58 -0
- data/test/matchers/controller/set_session_matcher_test.rb +31 -0
- data/test/matchers/controller/set_the_flash_matcher.rb +41 -0
- data/test/model_builder.rb +106 -0
- data/test/other/autoload_macro_test.rb +18 -0
- data/test/other/helpers_test.rb +58 -0
- data/test/other/private_helpers_test.rb +1 -1
- data/test/other/should_test.rb +16 -16
- data/test/rails_root/app/controllers/posts_controller.rb +6 -5
- data/test/rails_root/app/models/pets/dog.rb +10 -0
- data/test/rails_root/app/models/treat.rb +3 -0
- data/test/rails_root/app/models/user.rb +4 -3
- data/test/rails_root/app/views/layouts/posts.rhtml +2 -0
- data/test/rails_root/config/database.yml +1 -1
- data/test/rails_root/config/environment.rb +1 -1
- data/test/rails_root/config/environments/{sqlite3.rb → test.rb} +0 -0
- data/test/rails_root/db/migrate/001_create_users.rb +3 -2
- data/test/rails_root/db/migrate/011_create_treats.rb +12 -0
- data/test/rails_root/test/shoulda_macros/custom_macro.rb +6 -0
- data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +6 -0
- data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +6 -0
- data/test/rspec_test.rb +207 -0
- data/test/test_helper.rb +3 -1
- data/test/unit/address_test.rb +1 -23
- data/test/unit/dog_test.rb +5 -2
- data/test/unit/post_test.rb +7 -3
- data/test/unit/product_test.rb +2 -2
- data/test/unit/tag_test.rb +2 -1
- data/test/unit/user_test.rb +25 -9
- metadata +84 -23
- data/lib/shoulda/controller.rb +0 -30
- data/lib/shoulda/controller/formats/html.rb +0 -201
- data/lib/shoulda/controller/formats/xml.rb +0 -170
- data/lib/shoulda/controller/helpers.rb +0 -64
- data/lib/shoulda/controller/macros.rb +0 -316
- data/lib/shoulda/controller/resource_options.rb +0 -236
- data/test/rails_root/app/models/dog.rb +0 -5
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
3
|
class PrivateHelpersTest < Test::Unit::TestCase # :nodoc:
|
4
|
-
include
|
4
|
+
include Shoulda::Private
|
5
5
|
context "get_options!" do
|
6
6
|
should "remove opts from args" do
|
7
7
|
args = [:a, :b, {}]
|
data/test/other/should_test.rb
CHANGED
@@ -119,21 +119,21 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
|
|
119
119
|
|
120
120
|
def test_should_create_a_new_context
|
121
121
|
assert_nothing_raised do
|
122
|
-
|
122
|
+
Shoulda::Context.new("context name", self) do; end
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
def test_should_create_a_nested_context
|
127
127
|
assert_nothing_raised do
|
128
|
-
parent =
|
129
|
-
child =
|
128
|
+
parent = Shoulda::Context.new("Parent", self) do; end
|
129
|
+
child = Shoulda::Context.new("Child", parent) do; end
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
def test_should_name_a_contexts_correctly
|
134
|
-
parent =
|
135
|
-
child =
|
136
|
-
grandchild =
|
134
|
+
parent = Shoulda::Context.new("Parent", self) do; end
|
135
|
+
child = Shoulda::Context.new("Child", parent) do; end
|
136
|
+
grandchild = Shoulda::Context.new("GrandChild", child) do; end
|
137
137
|
|
138
138
|
assert_equal "Parent", parent.full_name
|
139
139
|
assert_equal "Parent Child", child.full_name
|
@@ -143,7 +143,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
|
|
143
143
|
# Should statements
|
144
144
|
|
145
145
|
def test_should_have_should_hashes_when_given_should_statements
|
146
|
-
context =
|
146
|
+
context = Shoulda::Context.new("name", self) do
|
147
147
|
should "be good" do; end
|
148
148
|
should "another" do; end
|
149
149
|
end
|
@@ -155,7 +155,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
|
|
155
155
|
# setup and teardown
|
156
156
|
|
157
157
|
def test_should_capture_setup_and_teardown_blocks
|
158
|
-
context =
|
158
|
+
context = Shoulda::Context.new("name", self) do
|
159
159
|
setup do; "setup"; end
|
160
160
|
teardown do; "teardown"; end
|
161
161
|
end
|
@@ -167,7 +167,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
|
|
167
167
|
# building
|
168
168
|
|
169
169
|
def test_should_create_shoulda_test_for_each_should_on_build
|
170
|
-
context =
|
170
|
+
context = Shoulda::Context.new("name", self) do
|
171
171
|
should "one" do; end
|
172
172
|
should "two" do; end
|
173
173
|
end
|
@@ -178,7 +178,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
|
|
178
178
|
|
179
179
|
def test_should_create_test_methods_on_build
|
180
180
|
tu_class = Test::Unit::TestCase
|
181
|
-
context =
|
181
|
+
context = Shoulda::Context.new("A Context", tu_class) do
|
182
182
|
should "define the test" do; end
|
183
183
|
end
|
184
184
|
|
@@ -188,7 +188,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
|
|
188
188
|
|
189
189
|
def test_should_create_test_methods_on_build_when_subcontext
|
190
190
|
tu_class = Test::Unit::TestCase
|
191
|
-
context =
|
191
|
+
context = Shoulda::Context.new("A Context", tu_class) do
|
192
192
|
context "with a child" do
|
193
193
|
should "define the test" do; end
|
194
194
|
end
|
@@ -203,21 +203,21 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
|
|
203
203
|
def test_should_create_a_new_context_and_build_it_on_Test_Unit_context
|
204
204
|
c = mock("context")
|
205
205
|
c.expects(:build)
|
206
|
-
|
206
|
+
Shoulda::Context.expects(:new).with("foo", kind_of(Class)).returns(c)
|
207
207
|
self.class.context "foo" do; end
|
208
208
|
end
|
209
209
|
|
210
210
|
def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should
|
211
211
|
s = mock("test")
|
212
|
-
|
213
|
-
|
212
|
+
Shoulda::Context.any_instance.expects(:should).with("rock", {}).returns(s)
|
213
|
+
Shoulda::Context.any_instance.expects(:build)
|
214
214
|
self.class.should "rock" do; end
|
215
215
|
end
|
216
216
|
|
217
217
|
def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should_eventually
|
218
218
|
s = mock("test")
|
219
|
-
|
220
|
-
|
219
|
+
Shoulda::Context.any_instance.expects(:should_eventually).with("rock").returns(s)
|
220
|
+
Shoulda::Context.any_instance.expects(:build)
|
221
221
|
self.class.should_eventually "rock" do; end
|
222
222
|
end
|
223
223
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class PostsController < ApplicationController
|
2
2
|
before_filter :ensure_logged_in
|
3
3
|
before_filter :load_user
|
4
|
-
|
4
|
+
|
5
5
|
def index
|
6
6
|
@posts = @user.posts
|
7
7
|
|
@@ -19,6 +19,7 @@ class PostsController < ApplicationController
|
|
19
19
|
|
20
20
|
def show
|
21
21
|
@post = @user.posts.find(params[:id])
|
22
|
+
@false_flag = false
|
22
23
|
|
23
24
|
respond_to do |format|
|
24
25
|
format.html { render :layout => 'wide' }
|
@@ -68,17 +69,17 @@ class PostsController < ApplicationController
|
|
68
69
|
def destroy
|
69
70
|
@post = @user.posts.find(params[:id])
|
70
71
|
@post.destroy
|
71
|
-
|
72
|
+
|
72
73
|
flash[:notice] = "Post was removed"
|
73
|
-
|
74
|
+
|
74
75
|
respond_to do |format|
|
75
76
|
format.html { redirect_to user_posts_url(@post.user) }
|
76
77
|
format.xml { head :ok }
|
77
78
|
end
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
private
|
81
|
-
|
82
|
+
|
82
83
|
def load_user
|
83
84
|
@user = User.find(params[:user_id])
|
84
85
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Pets
|
2
|
+
class Dog < ActiveRecord::Base
|
3
|
+
belongs_to :user, :foreign_key => :owner_id
|
4
|
+
belongs_to :address, :dependent => :destroy
|
5
|
+
has_many :treats
|
6
|
+
has_and_belongs_to_many :fleas, :join_table => :fleas
|
7
|
+
validates_presence_of :treats, :fleas
|
8
|
+
validates_presence_of :owner_id
|
9
|
+
end
|
10
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
2
|
has_many :posts
|
3
|
-
has_many :dogs, :foreign_key => :owner_id
|
3
|
+
has_many :dogs, :foreign_key => :owner_id, :class_name => "Pets::Dog"
|
4
4
|
|
5
5
|
has_many :friendships
|
6
6
|
has_many :friends, :through => :friendships
|
@@ -20,9 +20,10 @@ class User < ActiveRecord::Base
|
|
20
20
|
|
21
21
|
validates_format_of :email, :with => /\w*@\w*.com/
|
22
22
|
validates_length_of :email, :in => 1..100
|
23
|
-
|
23
|
+
validates_numericality_of :age, :greater_than_or_equal_to => 1,
|
24
|
+
:less_than_or_equal_to => 100
|
24
25
|
validates_acceptance_of :eula
|
25
|
-
validates_uniqueness_of :email, :scope => :name
|
26
|
+
validates_uniqueness_of :email, :scope => :name, :case_sensitive => false
|
26
27
|
validates_length_of :ssn, :is => 9, :message => "Social Security Number is not the right length"
|
27
28
|
validates_numericality_of :ssn
|
28
29
|
end
|
@@ -4,6 +4,8 @@
|
|
4
4
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
5
|
<head>
|
6
6
|
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<meta name="description" content="Posts, posts and more posts" />
|
8
|
+
<meta name='keywords' content='posts' />
|
7
9
|
<title>Posts: <%= controller.action_name %></title>
|
8
10
|
<%= stylesheet_link_tag 'scaffold' %>
|
9
11
|
</head>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
2
2
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
3
|
-
RAILS_GEM_VERSION = '
|
3
|
+
RAILS_GEM_VERSION = '= 2.2.2' unless defined? RAILS_GEM_VERSION
|
4
4
|
$VERBOSE = old_verbose
|
5
5
|
|
6
6
|
require File.join(File.dirname(__FILE__), 'boot')
|
File without changes
|
@@ -5,11 +5,12 @@ class CreateUsers < ActiveRecord::Migration
|
|
5
5
|
t.column :email, :string
|
6
6
|
t.column :age, :integer
|
7
7
|
t.column :ssn, :string
|
8
|
+
t.column :phone, :string
|
8
9
|
end
|
9
|
-
add_index :users, :email
|
10
|
+
add_index :users, :email, :unique => true
|
10
11
|
add_index :users, :name
|
11
12
|
add_index :users, :age
|
12
|
-
add_index :users, [:email, :name]
|
13
|
+
add_index :users, [:email, :name], :unique => true
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.down
|
data/test/rspec_test.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
gem 'rspec'
|
5
|
+
gem 'rspec-rails'
|
6
|
+
rescue LoadError => exception
|
7
|
+
puts exception.message
|
8
|
+
puts "RSpec integration was not tested because RSpec is not available"
|
9
|
+
else
|
10
|
+
|
11
|
+
class RspecTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
SHOULDA_ROOT =
|
14
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
15
|
+
|
16
|
+
def setup
|
17
|
+
build_gemspec
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
FileUtils.rm_rf(project_dir)
|
22
|
+
FileUtils.rm_rf("#{shoulda_root}/pkg")
|
23
|
+
end
|
24
|
+
|
25
|
+
should "integrate correctly when using config.gem in test.rb" do
|
26
|
+
create_project
|
27
|
+
insert(rspec_dependencies, "config/environments/test.rb")
|
28
|
+
vendor_gems('test')
|
29
|
+
configure_spec_rails
|
30
|
+
assert_configured
|
31
|
+
end
|
32
|
+
|
33
|
+
should "integrate correctly when using config.gem in environment.rb" do
|
34
|
+
create_project
|
35
|
+
insert(rspec_dependencies,
|
36
|
+
"config/environment.rb",
|
37
|
+
/Rails::Initializer\.run/)
|
38
|
+
vendor_gems('development')
|
39
|
+
configure_spec_rails
|
40
|
+
assert_configured
|
41
|
+
end
|
42
|
+
|
43
|
+
should "integrate correctly when using require in spec_helper" do
|
44
|
+
create_project
|
45
|
+
configure_spec_rails
|
46
|
+
insert(%{gem 'shoulda'; require 'shoulda'},
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
%{require 'spec/rails'})
|
49
|
+
assert_configured
|
50
|
+
end
|
51
|
+
|
52
|
+
should "integrate correctly when unpacked and required in spec_helper" do
|
53
|
+
create_project
|
54
|
+
configure_spec_rails
|
55
|
+
insert(%{require 'shoulda'},
|
56
|
+
"spec/spec_helper.rb",
|
57
|
+
%{require 'spec/rails'})
|
58
|
+
unpack_gems
|
59
|
+
assert_configured
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_project
|
63
|
+
command "rails #{project_dir}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def vendor_gems(env)
|
67
|
+
project_command "rake gems:unpack RAILS_ENV=#{env}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def unpack_gems
|
71
|
+
FileUtils.mkdir_p "#{project_dir}/vendor/gems"
|
72
|
+
FileUtils.cd "#{project_dir}/vendor/gems" do
|
73
|
+
%w(rspec rspec-rails shoulda).each do |gem|
|
74
|
+
command "gem unpack #{gem}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
insert('config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/*/lib"]',
|
79
|
+
"config/environment.rb",
|
80
|
+
/Rails::Initializer\.run/)
|
81
|
+
end
|
82
|
+
|
83
|
+
def command(command)
|
84
|
+
output = `GEM_PATH=#{shoulda_root}/pkg #{command} 2>&1`
|
85
|
+
unless $? == 0
|
86
|
+
flunk("Command failed with status #{$?}\n#{command}\n#{output}")
|
87
|
+
end
|
88
|
+
@command_output ||= ''
|
89
|
+
@command_output << output
|
90
|
+
output
|
91
|
+
end
|
92
|
+
|
93
|
+
def project_command(command)
|
94
|
+
result = nil
|
95
|
+
FileUtils.cd project_dir do
|
96
|
+
result = command(command)
|
97
|
+
end
|
98
|
+
result
|
99
|
+
end
|
100
|
+
|
101
|
+
def shoulda_command(command)
|
102
|
+
FileUtils.cd shoulda_root do
|
103
|
+
command(command)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def project_name
|
108
|
+
'example_rails_project'
|
109
|
+
end
|
110
|
+
|
111
|
+
def project_dir
|
112
|
+
File.expand_path(File.join(File.dirname(__FILE__), project_name))
|
113
|
+
end
|
114
|
+
|
115
|
+
def insert(content, path, after = nil)
|
116
|
+
path = File.join(project_dir, path)
|
117
|
+
contents = IO.read(path)
|
118
|
+
if after
|
119
|
+
contents.gsub!(/^(.*#{after}.*)$/, "\\1\n#{content}")
|
120
|
+
else
|
121
|
+
contents << "\n" << content
|
122
|
+
end
|
123
|
+
File.open(path, 'w') {|file| file.write(contents) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def rspec_dependencies
|
127
|
+
return <<-EOS
|
128
|
+
config.gem 'rspec', :lib => 'spec'
|
129
|
+
config.gem 'rspec-rails', :lib => false
|
130
|
+
config.gem 'shoulda', :lib => 'shoulda'
|
131
|
+
EOS
|
132
|
+
end
|
133
|
+
|
134
|
+
def configure_spec_rails
|
135
|
+
project_command "script/generate rspec"
|
136
|
+
end
|
137
|
+
|
138
|
+
def assert_configured
|
139
|
+
create_model
|
140
|
+
migrate
|
141
|
+
create_controller
|
142
|
+
assert_spec_passes
|
143
|
+
end
|
144
|
+
|
145
|
+
def create_model
|
146
|
+
project_command "script/generate rspec_model person name:string"
|
147
|
+
insert "validates_presence_of :name",
|
148
|
+
"app/models/person.rb",
|
149
|
+
/class Person/
|
150
|
+
insert "it { should validate_presence_of(:name) }",
|
151
|
+
"spec/models/person_spec.rb",
|
152
|
+
/describe Person do/
|
153
|
+
end
|
154
|
+
|
155
|
+
def create_controller
|
156
|
+
project_command "script/generate rspec_controller people"
|
157
|
+
insert "def index; render :text => 'Hello'; end",
|
158
|
+
"app/controllers/people_controller.rb",
|
159
|
+
/class PeopleController/
|
160
|
+
shoulda_controller_example = <<-EOS
|
161
|
+
describe PeopleController, "on GET index" do
|
162
|
+
integrate_views
|
163
|
+
subject { controller }
|
164
|
+
before(:each) { get :index }
|
165
|
+
it { should respond_with(:success) }
|
166
|
+
end
|
167
|
+
EOS
|
168
|
+
insert shoulda_controller_example,
|
169
|
+
"spec/controllers/people_controller_spec.rb"
|
170
|
+
end
|
171
|
+
|
172
|
+
def migrate
|
173
|
+
project_command "rake db:migrate"
|
174
|
+
end
|
175
|
+
|
176
|
+
def assert_spec_passes
|
177
|
+
result = project_command("rake spec SPEC_OPTS=-fs")
|
178
|
+
assert_match /should require name to be set/, result
|
179
|
+
assert_match /should respond with 200/, result
|
180
|
+
end
|
181
|
+
|
182
|
+
def shoulda_root
|
183
|
+
SHOULDA_ROOT
|
184
|
+
end
|
185
|
+
|
186
|
+
def build_gemspec
|
187
|
+
backup_gemspec do
|
188
|
+
shoulda_command "rake gemspec"
|
189
|
+
shoulda_command "rake gem"
|
190
|
+
shoulda_command "gem install --no-ri --no-rdoc -i pkg pkg/shoulda*.gem"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def backup_gemspec
|
195
|
+
actual = "#{shoulda_root}/shoulda.gemspec"
|
196
|
+
backup = "#{shoulda_root}/backup.gemspec"
|
197
|
+
FileUtils.mv(actual, backup)
|
198
|
+
begin
|
199
|
+
yield
|
200
|
+
ensure
|
201
|
+
FileUtils.mv(backup, actual)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|