rspec-rails 2.0.0.beta.4 → 2.0.0.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +32 -4
- data/VERSION +1 -1
- data/features/matchers/new_record_matcher.feature +25 -0
- data/features/model_specs/transactional_examples.feature +78 -0
- data/features/step_definitions/model_steps.rb +3 -0
- data/features/support/env.rb +37 -0
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb +4 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +0 -2
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +2 -2
- data/lib/rspec/rails/example/controller_example_group.rb +6 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -1
- data/lib/rspec/rails/example/view_example_group.rb +13 -1
- data/lib/rspec/rails/matchers.rb +8 -23
- data/lib/rspec/rails/mocks.rb +6 -6
- data/lib/rspec/rails/transactional_database_support.rb +10 -6
- data/rspec-rails.gemspec +24 -7
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +39 -0
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +8 -0
- data/spec/rspec/rails/matchers/render_template_spec.rb +8 -0
- data/spec/rspec/rails/transactional_database_support_spec.rb +54 -0
- data/spec/spec_helper.rb +23 -0
- data/specs.watchr +59 -0
- data/templates/generate_stuff.rb +2 -0
- data/templates/run_specs.rb +0 -2
- metadata +23 -9
data/Rakefile
CHANGED
@@ -5,6 +5,14 @@ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'lib'))
|
|
5
5
|
|
6
6
|
require 'rake/rdoctask'
|
7
7
|
require 'rspec/rails/version'
|
8
|
+
require 'rspec'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
require 'cucumber/rake/task'
|
11
|
+
|
12
|
+
Rspec::Core::RakeTask.new(:spec)
|
13
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
14
|
+
t.cucumber_opts = %w{--format progress}
|
15
|
+
end
|
8
16
|
|
9
17
|
begin
|
10
18
|
require 'jeweler'
|
@@ -59,8 +67,10 @@ end
|
|
59
67
|
|
60
68
|
namespace :generate do
|
61
69
|
desc "generate a fresh app with rspec installed"
|
62
|
-
task :app => ["rails:clone"
|
63
|
-
|
70
|
+
task :app => ["rails:clone"] do |t|
|
71
|
+
unless File.directory?('./tmp/example_app')
|
72
|
+
ruby "./tmp/rails/railties/bin/rails tmp/example_app --dev -m example_app_template.rb"
|
73
|
+
end
|
64
74
|
end
|
65
75
|
|
66
76
|
desc "generate a bunch of stuff with generators"
|
@@ -71,8 +81,26 @@ namespace :generate do
|
|
71
81
|
end
|
72
82
|
end
|
73
83
|
|
84
|
+
namespace :db do
|
85
|
+
task :migrate do
|
86
|
+
Dir.chdir("./tmp/example_app/") do
|
87
|
+
sh "rake db:migrate"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
namespace :test do
|
92
|
+
task :prepare do
|
93
|
+
Dir.chdir("./tmp/example_app/") do
|
94
|
+
sh "rake db:test:prepare"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
|
74
102
|
desc "run a variety of specs against the generated app"
|
75
|
-
task :
|
103
|
+
task :smoke do
|
76
104
|
Dir.chdir("./tmp/example_app/") do
|
77
105
|
sh "rake rails:template LOCATION='../../templates/run_specs.rb'"
|
78
106
|
end
|
@@ -87,5 +115,5 @@ task :clobber_app do
|
|
87
115
|
rm_rf "tmp/example_app"
|
88
116
|
end
|
89
117
|
|
90
|
-
task :default => ["generate:app", "generate:stuff", :
|
118
|
+
task :default => [:clobber_app, "generate:app", "generate:stuff", :spec, :cucumber, :smoke]
|
91
119
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.beta.
|
1
|
+
2.0.0.beta.5
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Feature: be_a_new matcher
|
2
|
+
|
3
|
+
The be_a_new matcher accepts a class and passes if the subject is an instance
|
4
|
+
of that class that returns true to new_record?
|
5
|
+
|
6
|
+
Scenario: example spec with four possibilities
|
7
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
8
|
+
"""
|
9
|
+
require "spec_helper"
|
10
|
+
|
11
|
+
describe Widget do
|
12
|
+
context "when initialized" do
|
13
|
+
subject { Widget.new }
|
14
|
+
it { should be_a_new(Widget) }
|
15
|
+
it { should_not be_a_new(String) }
|
16
|
+
end
|
17
|
+
context "when saved" do
|
18
|
+
subject { Widget.create }
|
19
|
+
it { should_not be_a_new(Widget) }
|
20
|
+
it { should_not be_a_new(String) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
"""
|
24
|
+
When I run "rspec spec/models/widget_spec.rb"
|
25
|
+
Then I should see "4 examples, 0 failures"
|
@@ -0,0 +1,78 @@
|
|
1
|
+
Feature: transactional examples
|
2
|
+
|
3
|
+
Scenario: run in transactions (default)
|
4
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
5
|
+
"""
|
6
|
+
require "spec_helper"
|
7
|
+
|
8
|
+
describe Widget do
|
9
|
+
it "has none to begin with" do
|
10
|
+
Widget.count.should == 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has one after adding one" do
|
14
|
+
Widget.create
|
15
|
+
Widget.count.should == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has none after one was created in a previous example" do
|
19
|
+
Widget.count.should == 0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
"""
|
23
|
+
When I run "rspec spec/models/widget_spec.rb"
|
24
|
+
Then I should see "3 examples, 0 failures"
|
25
|
+
|
26
|
+
Scenario: run in transactions (explicit)
|
27
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
28
|
+
"""
|
29
|
+
require "spec_helper"
|
30
|
+
|
31
|
+
Rspec.configure do |c|
|
32
|
+
c.use_transactional_examples = true
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Widget do
|
36
|
+
it "has none to begin with" do
|
37
|
+
Widget.count.should == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has one after adding one" do
|
41
|
+
Widget.create
|
42
|
+
Widget.count.should == 1
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has none after one was created in a previous example" do
|
46
|
+
Widget.count.should == 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
"""
|
50
|
+
When I run "rspec spec/models/widget_spec.rb"
|
51
|
+
Then I should see "3 examples, 0 failures"
|
52
|
+
|
53
|
+
Scenario: disable transactions (explicit)
|
54
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
55
|
+
"""
|
56
|
+
require "spec_helper"
|
57
|
+
|
58
|
+
Rspec.configure do |c|
|
59
|
+
c.use_transactional_examples = false
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Widget do
|
63
|
+
it "has none to begin with" do
|
64
|
+
Widget.count.should == 0
|
65
|
+
end
|
66
|
+
|
67
|
+
it "has one after adding one" do
|
68
|
+
Widget.create
|
69
|
+
Widget.count.should == 1
|
70
|
+
end
|
71
|
+
|
72
|
+
it "has one after one was created in a previous example" do
|
73
|
+
Widget.count.should == 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
"""
|
77
|
+
When I run "rspec spec/models/widget_spec.rb"
|
78
|
+
Then I should see "3 examples, 0 failures"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "aruba"
|
2
|
+
require "rspec/expectations"
|
3
|
+
|
4
|
+
unless File.directory?('./tmp/example_app')
|
5
|
+
system "rake generate:app generate:stuff"
|
6
|
+
end
|
7
|
+
|
8
|
+
def aruba_path(file_or_dir)
|
9
|
+
File.expand_path("../../../#{file_or_dir.sub('example_app','aruba')}", __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def example_app_path(file_or_dir)
|
13
|
+
File.expand_path("../../../#{file_or_dir}", __FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_symlink(file_or_dir)
|
17
|
+
source = example_app_path(file_or_dir)
|
18
|
+
target = aruba_path(file_or_dir)
|
19
|
+
system "ln -s #{source} #{target}"
|
20
|
+
end
|
21
|
+
|
22
|
+
Before do
|
23
|
+
steps %Q{
|
24
|
+
Given a directory named "spec"
|
25
|
+
}
|
26
|
+
|
27
|
+
Dir['tmp/example_app/*'].each do |file_or_dir|
|
28
|
+
unless file_or_dir =~ /spec$/
|
29
|
+
write_symlink(file_or_dir)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
["spec/spec_helper.rb"].each do |file_or_dir|
|
34
|
+
write_symlink("tmp/example_app/#{file_or_dir}")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -17,4 +17,8 @@ Rspec.configure do |config|
|
|
17
17
|
# config.mock_with :flexmock
|
18
18
|
# config.mock_with :rr
|
19
19
|
config.mock_with :rspec
|
20
|
+
|
21
|
+
# If you'd prefer not to run each of your examples within a transaction,
|
22
|
+
# uncomment the following line.
|
23
|
+
# config.use_transactional_examples false
|
20
24
|
end
|
@@ -66,7 +66,7 @@ describe <%= controller_class_name %>Controller do
|
|
66
66
|
it "re-renders the 'new' template" do
|
67
67
|
<%= stub! orm_class.build(class_name) %> { <%= mock_file_name(:save => false) %> }
|
68
68
|
post :create, :<%= file_name %> => {}
|
69
|
-
response.should render_template(
|
69
|
+
response.should render_template(:new)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -104,7 +104,7 @@ describe <%= controller_class_name %>Controller do
|
|
104
104
|
it "re-renders the 'edit' template" do
|
105
105
|
<%= stub! orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => false) %> }
|
106
106
|
put :update, :id => "1"
|
107
|
-
response.should render_template(
|
107
|
+
response.should render_template(:edit)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -14,7 +14,12 @@ module ControllerExampleGroupBehaviour
|
|
14
14
|
include ActionDispatch::Integration::Runner
|
15
15
|
include Webrat::Matchers
|
16
16
|
include Webrat::Methods
|
17
|
-
include Rspec::
|
17
|
+
include Rspec::Matchers
|
18
|
+
|
19
|
+
def self.setup(*args); end
|
20
|
+
def self.teardown(*args); end
|
21
|
+
|
22
|
+
include ActionController::TemplateAssertions
|
18
23
|
|
19
24
|
def self.included(mod)
|
20
25
|
mod.before do
|
@@ -8,10 +8,22 @@ module ViewExampleGroupBehaviour
|
|
8
8
|
attr_accessor :controller_path
|
9
9
|
end
|
10
10
|
|
11
|
+
module ViewExtension
|
12
|
+
def protect_against_forgery?; end
|
13
|
+
def method_missing(selector, *args)
|
14
|
+
if Rails.application.routes.named_routes.helpers.include?(selector)
|
15
|
+
controller.__send__(selector, *args)
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
def view
|
12
23
|
@view ||= begin
|
13
24
|
view = ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
|
14
|
-
view.extend(
|
25
|
+
view.extend(ActionController::PolymorphicRoutes)
|
26
|
+
view.extend(ViewExtension)
|
15
27
|
view
|
16
28
|
end
|
17
29
|
end
|
data/lib/rspec/rails/matchers.rb
CHANGED
@@ -11,30 +11,15 @@ rescue LoadError
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def redirect_to(destination)
|
20
|
-
running_example = self
|
21
|
-
Matcher.new :redirect_to, destination do |destination_|
|
22
|
-
match_unless_raises Test::Unit::AssertionFailedError do |_|
|
23
|
-
running_example.assert_redirected_to destination_
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def render_template(options={}, message=nil)
|
29
|
-
running_example = self
|
30
|
-
Matcher.new :render_template, options, message do |options_, message_|
|
31
|
-
match_unless_raises Test::Unit::AssertionFailedError do |_|
|
32
|
-
running_example.assert_template options_, message_
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
14
|
+
Rspec::Matchers.define :redirect_to do |destination|
|
15
|
+
match_unless_raises Test::Unit::AssertionFailedError do |_|
|
16
|
+
assert_redirected_to destination
|
17
|
+
end
|
18
|
+
end
|
36
19
|
|
37
|
-
|
20
|
+
Rspec::Matchers.define :render_template do |options, message|
|
21
|
+
match_unless_raises Test::Unit::AssertionFailedError do |_|
|
22
|
+
assert_template options, message
|
38
23
|
end
|
39
24
|
end
|
40
25
|
|
data/lib/rspec/rails/mocks.rb
CHANGED
@@ -20,25 +20,25 @@ module Rspec
|
|
20
20
|
derived_name = "#{model_class.name}_#{id}"
|
21
21
|
m = mock(derived_name, options_and_stubs)
|
22
22
|
m.__send__(:__mock_proxy).instance_eval <<-CODE
|
23
|
-
def @
|
23
|
+
def @object.as_new_record
|
24
24
|
self.stub(:id) { nil }
|
25
25
|
self.stub(:to_param) { nil }
|
26
26
|
self.stub(:new_record?) { true }
|
27
27
|
self
|
28
28
|
end
|
29
|
-
def @
|
29
|
+
def @object.is_a?(other)
|
30
30
|
#{model_class}.ancestors.include?(other)
|
31
31
|
end
|
32
|
-
def @
|
32
|
+
def @object.kind_of?(other)
|
33
33
|
#{model_class}.ancestors.include?(other)
|
34
34
|
end
|
35
|
-
def @
|
35
|
+
def @object.instance_of?(other)
|
36
36
|
other == #{model_class}
|
37
37
|
end
|
38
|
-
def @
|
38
|
+
def @object.class
|
39
39
|
#{model_class}
|
40
40
|
end
|
41
|
-
def @
|
41
|
+
def @object.to_s
|
42
42
|
"#{model_class.name}_#{id}"
|
43
43
|
end
|
44
44
|
CODE
|
@@ -8,15 +8,19 @@ module Rspec
|
|
8
8
|
defined?(::ActiveRecord) && !::ActiveRecord::Base.configurations.blank?
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def use_transactional_examples?
|
12
|
+
active_record_configured? && Rspec.configuration.use_transactional_examples?
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup_transactional_examples
|
16
|
+
return unless use_transactional_examples?
|
13
17
|
|
14
18
|
::ActiveRecord::Base.connection.increment_open_transactions
|
15
19
|
::ActiveRecord::Base.connection.begin_db_transaction
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
return unless
|
22
|
+
def teardown_transactional_examples
|
23
|
+
return unless use_transactional_examples?
|
20
24
|
|
21
25
|
if ::ActiveRecord::Base.connection.open_transactions != 0
|
22
26
|
::ActiveRecord::Base.connection.rollback_db_transaction
|
@@ -32,7 +36,7 @@ end
|
|
32
36
|
|
33
37
|
Rspec.configure do |c|
|
34
38
|
c.include Rspec::Rails::TransactionalDatabaseSupport
|
35
|
-
c.before {
|
36
|
-
c.after
|
39
|
+
c.before { setup_transactional_examples }
|
40
|
+
c.after { teardown_transactional_examples }
|
37
41
|
end
|
38
42
|
|
data/rspec-rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rspec-rails}
|
8
|
-
s.version = "2.0.0.beta.
|
8
|
+
s.version = "2.0.0.beta.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Chelimsky", "Chad Humphries"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-04}
|
13
13
|
s.description = %q{Rspec-2 for Rails-3}
|
14
14
|
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,6 +21,10 @@ Gem::Specification.new do |s|
|
|
21
21
|
"Rakefile",
|
22
22
|
"VERSION",
|
23
23
|
"example_app_template.rb",
|
24
|
+
"features/matchers/new_record_matcher.feature",
|
25
|
+
"features/model_specs/transactional_examples.feature",
|
26
|
+
"features/step_definitions/model_steps.rb",
|
27
|
+
"features/support/env.rb",
|
24
28
|
"lib/generators/rspec.rb",
|
25
29
|
"lib/generators/rspec/controller/controller_generator.rb",
|
26
30
|
"lib/generators/rspec/controller/templates/controller_spec.rb",
|
@@ -63,13 +67,19 @@ Gem::Specification.new do |s|
|
|
63
67
|
"lib/rspec/rails/transactional_database_support.rb",
|
64
68
|
"lib/rspec/rails/version.rb",
|
65
69
|
"rspec-rails.gemspec",
|
70
|
+
"spec/rspec/rails/matchers/be_a_new_spec.rb",
|
71
|
+
"spec/rspec/rails/matchers/redirect_to_spec.rb",
|
72
|
+
"spec/rspec/rails/matchers/render_template_spec.rb",
|
73
|
+
"spec/rspec/rails/transactional_database_support_spec.rb",
|
74
|
+
"spec/spec_helper.rb",
|
75
|
+
"specs.watchr",
|
66
76
|
"templates/generate_stuff.rb",
|
67
77
|
"templates/run_specs.rb"
|
68
78
|
]
|
69
79
|
s.homepage = %q{http://github.com/rspec/rspec-rails}
|
70
80
|
s.post_install_message = %q{**************************************************
|
71
81
|
|
72
|
-
Thank you for installing rspec-rails-2.0.0.beta.
|
82
|
+
Thank you for installing rspec-rails-2.0.0.beta.5!
|
73
83
|
|
74
84
|
This version of rspec-rails only works with
|
75
85
|
versions of rails >= 3.0.0.pre.
|
@@ -84,21 +94,28 @@ Gem::Specification.new do |s|
|
|
84
94
|
s.require_paths = ["lib"]
|
85
95
|
s.rubyforge_project = %q{rspec}
|
86
96
|
s.rubygems_version = %q{1.3.6}
|
87
|
-
s.summary = %q{rspec-rails-2.0.0.beta.
|
97
|
+
s.summary = %q{rspec-rails-2.0.0.beta.5}
|
98
|
+
s.test_files = [
|
99
|
+
"spec/rspec/rails/matchers/be_a_new_spec.rb",
|
100
|
+
"spec/rspec/rails/matchers/redirect_to_spec.rb",
|
101
|
+
"spec/rspec/rails/matchers/render_template_spec.rb",
|
102
|
+
"spec/rspec/rails/transactional_database_support_spec.rb",
|
103
|
+
"spec/spec_helper.rb"
|
104
|
+
]
|
88
105
|
|
89
106
|
if s.respond_to? :specification_version then
|
90
107
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
91
108
|
s.specification_version = 3
|
92
109
|
|
93
110
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
94
|
-
s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.
|
111
|
+
s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.5"])
|
95
112
|
s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
|
96
113
|
else
|
97
|
-
s.add_dependency(%q<rspec>, ["= 2.0.0.beta.
|
114
|
+
s.add_dependency(%q<rspec>, ["= 2.0.0.beta.5"])
|
98
115
|
s.add_dependency(%q<webrat>, [">= 0.7.0"])
|
99
116
|
end
|
100
117
|
else
|
101
|
-
s.add_dependency(%q<rspec>, ["= 2.0.0.beta.
|
118
|
+
s.add_dependency(%q<rspec>, ["= 2.0.0.beta.5"])
|
102
119
|
s.add_dependency(%q<webrat>, [">= 0.7.0"])
|
103
120
|
end
|
104
121
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "be_a_new matcher" do
|
4
|
+
context "new record" do
|
5
|
+
let(:record) do
|
6
|
+
Class.new do
|
7
|
+
def new_record?; true; end
|
8
|
+
end.new
|
9
|
+
end
|
10
|
+
context "right class" do
|
11
|
+
it "passes" do
|
12
|
+
record.should be_a_new(record.class)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context "wrong class" do
|
16
|
+
it "fails" do
|
17
|
+
record.should_not be_a_new(String)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "existing record" do
|
23
|
+
let(:record) do
|
24
|
+
Class.new do
|
25
|
+
def new_record?; false; end
|
26
|
+
end.new
|
27
|
+
end
|
28
|
+
context "right class" do
|
29
|
+
it "fails" do
|
30
|
+
record.should_not be_a_new(record.class)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context "wrong class" do
|
34
|
+
it "fails" do
|
35
|
+
record.should_not be_a_new(String)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rspec::Rails::TransactionalDatabaseSupport do
|
4
|
+
|
5
|
+
let(:connection) { double('connection', :open_transactions => 1) }
|
6
|
+
let(:test_bed) do
|
7
|
+
Class.new do
|
8
|
+
include Rspec::Rails::TransactionalDatabaseSupport
|
9
|
+
def active_record_configured?; true; end
|
10
|
+
end.new
|
11
|
+
end
|
12
|
+
|
13
|
+
before { ::ActiveRecord::Base.stub(:connection) { connection } }
|
14
|
+
|
15
|
+
describe "#setup_transactional_examples" do
|
16
|
+
context 'when running with examples with transactions' do
|
17
|
+
it "opens a new transaction" do
|
18
|
+
test_bed.stub(:use_transactional_examples?) { true }
|
19
|
+
connection.should_receive(:increment_open_transactions)
|
20
|
+
connection.should_receive(:begin_db_transaction)
|
21
|
+
test_bed.setup_transactional_examples
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with transactionless examples' do
|
26
|
+
it "doesn't open a transaction" do
|
27
|
+
test_bed.stub(:use_transactional_examples?) { false }
|
28
|
+
connection.should_not_receive(:increment_open_transactions)
|
29
|
+
connection.should_not_receive(:begin_db_transaction)
|
30
|
+
test_bed.setup_transactional_examples
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#teardown_transactional_examples" do
|
36
|
+
context 'when running with examples with transactions' do
|
37
|
+
it "opens a new transaction" do
|
38
|
+
test_bed.stub(:use_transactional_examples?) { true }
|
39
|
+
connection.should_receive(:rollback_db_transaction)
|
40
|
+
connection.should_receive(:decrement_open_transactions)
|
41
|
+
test_bed.teardown_transactional_examples
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with transactionless examples' do
|
46
|
+
it "doesn't close an open transaction" do
|
47
|
+
test_bed.stub(:use_transactional_examples?) { false }
|
48
|
+
connection.should_not_receive(:decrement_open_transactions)
|
49
|
+
connection.should_not_receive(:rollback_db_transaction)
|
50
|
+
test_bed.teardown_transactional_examples
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
%w(actionmailer actionpack activemodel activerecord activeresource activesupport railties).each do |directory|
|
2
|
+
$LOAD_PATH.unshift File.expand_path( File.join(File.dirname(__FILE__), "..", "tmp", "rails", directory, "lib") )
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'i18n'
|
6
|
+
require 'rack'
|
7
|
+
require 'rack/mock'
|
8
|
+
require 'rack/mime'
|
9
|
+
require 'active_support'
|
10
|
+
require 'active_support/core_ext'
|
11
|
+
require 'action_dispatch'
|
12
|
+
require 'action_controller'
|
13
|
+
require 'active_record'
|
14
|
+
require 'rspec/rails'
|
15
|
+
|
16
|
+
def in_editor?
|
17
|
+
ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
|
18
|
+
end
|
19
|
+
|
20
|
+
Rspec.configure do |c|
|
21
|
+
c.color_enabled = !in_editor?
|
22
|
+
end
|
23
|
+
|
data/specs.watchr
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Run me with:
|
2
|
+
#
|
3
|
+
# $ watchr specs.watchr
|
4
|
+
|
5
|
+
# --------------------------------------------------
|
6
|
+
# Convenience Methods
|
7
|
+
# --------------------------------------------------
|
8
|
+
def all_test_files
|
9
|
+
Dir['spec/**/*_spec.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
def run_test_matching(thing_to_match)
|
13
|
+
matches = all_test_files.grep(/#{thing_to_match}/i)
|
14
|
+
if matches.empty?
|
15
|
+
puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
|
16
|
+
else
|
17
|
+
run matches.join(' ')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(files_to_run)
|
22
|
+
puts("Running: #{files_to_run}")
|
23
|
+
system("clear;rspec -cfs #{files_to_run}")
|
24
|
+
no_int_for_you
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_all_tests
|
28
|
+
run(all_test_files.join(' '))
|
29
|
+
end
|
30
|
+
|
31
|
+
# --------------------------------------------------
|
32
|
+
# Watchr Rules
|
33
|
+
# --------------------------------------------------
|
34
|
+
watch('^spec/(.*)_spec\.rb') { |m| run_test_matching(m[1]) }
|
35
|
+
watch('^lib/(.*)\.rb') { |m| run_test_matching(m[1]) }
|
36
|
+
watch('^spec/spec_helper\.rb') { run_all_tests }
|
37
|
+
watch('^spec/support/.*\.rb') { run_all_tests }
|
38
|
+
|
39
|
+
# --------------------------------------------------
|
40
|
+
# Signal Handling
|
41
|
+
# --------------------------------------------------
|
42
|
+
|
43
|
+
def no_int_for_you
|
44
|
+
@sent_an_int = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
Signal.trap 'INT' do
|
48
|
+
if @sent_an_int then
|
49
|
+
puts " A second INT? Ok, I get the message. Shutting down now."
|
50
|
+
exit
|
51
|
+
else
|
52
|
+
puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
|
53
|
+
@sent_an_int = true
|
54
|
+
Kernel.sleep 1.5
|
55
|
+
run_all_tests
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# vim:ft=ruby
|
data/templates/generate_stuff.rb
CHANGED
data/templates/run_specs.rb
CHANGED
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 2.0.0.beta.
|
10
|
+
- 5
|
11
|
+
version: 2.0.0.beta.5
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- David Chelimsky
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-
|
20
|
+
date: 2010-04-04 00:00:00 -03:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -32,8 +32,8 @@ dependencies:
|
|
32
32
|
- 0
|
33
33
|
- 0
|
34
34
|
- beta
|
35
|
-
-
|
36
|
-
version: 2.0.0.beta.
|
35
|
+
- 5
|
36
|
+
version: 2.0.0.beta.5
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
@@ -64,6 +64,10 @@ files:
|
|
64
64
|
- Rakefile
|
65
65
|
- VERSION
|
66
66
|
- example_app_template.rb
|
67
|
+
- features/matchers/new_record_matcher.feature
|
68
|
+
- features/model_specs/transactional_examples.feature
|
69
|
+
- features/step_definitions/model_steps.rb
|
70
|
+
- features/support/env.rb
|
67
71
|
- lib/generators/rspec.rb
|
68
72
|
- lib/generators/rspec/controller/controller_generator.rb
|
69
73
|
- lib/generators/rspec/controller/templates/controller_spec.rb
|
@@ -106,6 +110,12 @@ files:
|
|
106
110
|
- lib/rspec/rails/transactional_database_support.rb
|
107
111
|
- lib/rspec/rails/version.rb
|
108
112
|
- rspec-rails.gemspec
|
113
|
+
- spec/rspec/rails/matchers/be_a_new_spec.rb
|
114
|
+
- spec/rspec/rails/matchers/redirect_to_spec.rb
|
115
|
+
- spec/rspec/rails/matchers/render_template_spec.rb
|
116
|
+
- spec/rspec/rails/transactional_database_support_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- specs.watchr
|
109
119
|
- templates/generate_stuff.rb
|
110
120
|
- templates/run_specs.rb
|
111
121
|
has_rdoc: true
|
@@ -115,7 +125,7 @@ licenses: []
|
|
115
125
|
post_install_message: |
|
116
126
|
**************************************************
|
117
127
|
|
118
|
-
Thank you for installing rspec-rails-2.0.0.beta.
|
128
|
+
Thank you for installing rspec-rails-2.0.0.beta.5!
|
119
129
|
|
120
130
|
This version of rspec-rails only works with
|
121
131
|
versions of rails >= 3.0.0.pre.
|
@@ -152,6 +162,10 @@ rubyforge_project: rspec
|
|
152
162
|
rubygems_version: 1.3.6
|
153
163
|
signing_key:
|
154
164
|
specification_version: 3
|
155
|
-
summary: rspec-rails-2.0.0.beta.
|
156
|
-
test_files:
|
157
|
-
|
165
|
+
summary: rspec-rails-2.0.0.beta.5
|
166
|
+
test_files:
|
167
|
+
- spec/rspec/rails/matchers/be_a_new_spec.rb
|
168
|
+
- spec/rspec/rails/matchers/redirect_to_spec.rb
|
169
|
+
- spec/rspec/rails/matchers/render_template_spec.rb
|
170
|
+
- spec/rspec/rails/transactional_database_support_spec.rb
|
171
|
+
- spec/spec_helper.rb
|