rspec-rails 2.0.0.beta.5 → 2.0.0.beta.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -63,6 +63,14 @@ namespace :rails do
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ desc "update the rails repo"
68
+ task :update => :clone do
69
+ Dir.chdir('tmp/rails') do
70
+ sh "git checkout master"
71
+ sh "git pull"
72
+ end
73
+ end
66
74
  end
67
75
 
68
76
  namespace :generate do
@@ -97,8 +105,6 @@ namespace :db do
97
105
  end
98
106
  end
99
107
 
100
-
101
-
102
108
  desc "run a variety of specs against the generated app"
103
109
  task :smoke do
104
110
  Dir.chdir("./tmp/example_app/") do
@@ -111,9 +117,12 @@ task :clobber do
111
117
  rm_rf "pkg"
112
118
  end
113
119
 
114
- task :clobber_app do
115
- rm_rf "tmp/example_app"
120
+ namespace :clobber do
121
+ desc "clobber the generated app"
122
+ task :app do
123
+ rm_rf "tmp/example_app"
124
+ end
116
125
  end
117
126
 
118
- task :default => [:clobber_app, "generate:app", "generate:stuff", :spec, :cucumber, :smoke]
127
+ task :default => ["clobber:app", "generate:app", "generate:stuff", :spec, :cucumber, :smoke]
119
128
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.5
1
+ 2.0.0.beta.6
@@ -0,0 +1,76 @@
1
+ # (c) Copyright 2006 Nick Sieger <nicksieger@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation files
5
+ # (the "Software"), to deal in the Software without restriction,
6
+ # including without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ $:.push(*Dir["vendor/rails/*/lib"])
24
+
25
+ require 'active_support'
26
+ require 'autotest/rspec2'
27
+
28
+ Autotest.add_hook :initialize do |at|
29
+ %w{config/ coverage/ db/ doc/ log/ public/ script/ tmp/ vendor/rails vendor/plugins previous_failures.txt}.each do |exception|
30
+ at.add_exception(exception)
31
+ end
32
+
33
+ at.clear_mappings
34
+
35
+ at.add_mapping(%r%^(test|spec)/fixtures/(.*).yml$%) { |_, m|
36
+ ["spec/models/#{m[2].singularize}_spec.rb"] + at.files_matching(%r%^spec\/views\/#{m[2]}/.*_spec\.rb$%)
37
+ }
38
+ at.add_mapping(%r%^spec/(models|controllers|routing|views|helpers|lib)/.*rb$%) { |filename, _|
39
+ filename
40
+ }
41
+ at.add_mapping(%r%^app/models/(.*)\.rb$%) { |_, m|
42
+ ["spec/models/#{m[1]}_spec.rb"]
43
+ }
44
+ at.add_mapping(%r%^app/views/(.*)$%) { |_, m|
45
+ at.files_matching %r%^spec/views/#{m[1]}_spec.rb$%
46
+ }
47
+ at.add_mapping(%r%^app/controllers/(.*)\.rb$%) { |_, m|
48
+ if m[1] == "application"
49
+ at.files_matching %r%^spec/controllers/.*_spec\.rb$%
50
+ else
51
+ ["spec/controllers/#{m[1]}_spec.rb"]
52
+ end
53
+ }
54
+ at.add_mapping(%r%^app/helpers/(.*)_helper\.rb$%) { |_, m|
55
+ if m[1] == "application" then
56
+ at.files_matching(%r%^spec/(views|helpers)/.*_spec\.rb$%)
57
+ else
58
+ ["spec/helpers/#{m[1]}_helper_spec.rb"] + at.files_matching(%r%^spec\/views\/#{m[1]}/.*_spec\.rb$%)
59
+ end
60
+ }
61
+ at.add_mapping(%r%^config/routes\.rb$%) {
62
+ at.files_matching %r%^spec/(controllers|routing|views|helpers)/.*_spec\.rb$%
63
+ }
64
+ at.add_mapping(%r%^config/database\.yml$%) { |_, m|
65
+ at.files_matching %r%^spec/models/.*_spec\.rb$%
66
+ }
67
+ at.add_mapping(%r%^(spec/(spec_helper|shared/.*)|config/(boot|environment(s/test)?))\.rb$%) {
68
+ at.files_matching %r%^spec/(models|controllers|routing|views|helpers)/.*_spec\.rb$%
69
+ }
70
+ at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
71
+ ["spec/lib/#{m[1]}_spec.rb"]
72
+ }
73
+ end
74
+
75
+ class Autotest::RailsRspec2 < Autotest::Rspec2
76
+ end
@@ -25,6 +25,10 @@ DESC
25
25
  directory 'spec'
26
26
  end
27
27
 
28
+ def copy_autotest_discover_file
29
+ directory 'autotest'
30
+ end
31
+
28
32
  def app_name
29
33
  Rails.application.class.name
30
34
  end
@@ -0,0 +1,2 @@
1
+ Autotest.add_discovery { "rails" }
2
+ Autotest.add_discovery { "rspec2" }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe <%= class_name.pluralize %> do
3
+ describe "<%= class_name.pluralize %>" do
4
4
  describe "GET /<%= table_name %>" do
5
5
  it "works! (now write some real specs)" do
6
6
  get <%= table_name %>_path
@@ -15,11 +15,12 @@ module Rspec
15
15
  :to_param => id.to_s,
16
16
  :new_record? => false,
17
17
  :destroyed? => false,
18
+ :marked_for_destruction? => false,
18
19
  :errors => stub("errors", :count => 0)
19
20
  })
20
21
  derived_name = "#{model_class.name}_#{id}"
21
22
  m = mock(derived_name, options_and_stubs)
22
- m.__send__(:__mock_proxy).instance_eval <<-CODE
23
+ m.__send__(:__mock_proxy).instance_eval(<<-CODE, __FILE__, __LINE__)
23
24
  def @object.as_new_record
24
25
  self.stub(:id) { nil }
25
26
  self.stub(:to_param) { nil }
@@ -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.5"
8
+ s.version = "2.0.0.beta.6"
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-04-04}
12
+ s.date = %q{2010-04-12}
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 = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "features/model_specs/transactional_examples.feature",
26
26
  "features/step_definitions/model_steps.rb",
27
27
  "features/support/env.rb",
28
+ "lib/autotest/rails_rspec2.rb",
28
29
  "lib/generators/rspec.rb",
29
30
  "lib/generators/rspec/controller/controller_generator.rb",
30
31
  "lib/generators/rspec/controller/templates/controller_spec.rb",
@@ -32,9 +33,9 @@ Gem::Specification.new do |s|
32
33
  "lib/generators/rspec/helper/helper_generator.rb",
33
34
  "lib/generators/rspec/helper/templates/helper_spec.rb",
34
35
  "lib/generators/rspec/install/install_generator.rb",
36
+ "lib/generators/rspec/install/templates/autotest/discover.rb",
35
37
  "lib/generators/rspec/install/templates/config/initializers/rspec_generator.rb.tt",
36
38
  "lib/generators/rspec/install/templates/lib/tasks/rspec.rake",
37
- "lib/generators/rspec/install/templates/spec/spec.opts",
38
39
  "lib/generators/rspec/install/templates/spec/spec_helper.rb",
39
40
  "lib/generators/rspec/integration/integration_generator.rb",
40
41
  "lib/generators/rspec/integration/templates/request_spec.rb",
@@ -70,6 +71,9 @@ Gem::Specification.new do |s|
70
71
  "spec/rspec/rails/matchers/be_a_new_spec.rb",
71
72
  "spec/rspec/rails/matchers/redirect_to_spec.rb",
72
73
  "spec/rspec/rails/matchers/render_template_spec.rb",
74
+ "spec/rspec/rails/mocks/ar_classes.rb",
75
+ "spec/rspec/rails/mocks/mock_model_spec.rb",
76
+ "spec/rspec/rails/mocks/stub_model_spec.rb",
73
77
  "spec/rspec/rails/transactional_database_support_spec.rb",
74
78
  "spec/spec_helper.rb",
75
79
  "specs.watchr",
@@ -79,7 +83,7 @@ Gem::Specification.new do |s|
79
83
  s.homepage = %q{http://github.com/rspec/rspec-rails}
80
84
  s.post_install_message = %q{**************************************************
81
85
 
82
- Thank you for installing rspec-rails-2.0.0.beta.5!
86
+ Thank you for installing rspec-rails-2.0.0.beta.6!
83
87
 
84
88
  This version of rspec-rails only works with
85
89
  versions of rails >= 3.0.0.pre.
@@ -94,11 +98,14 @@ Gem::Specification.new do |s|
94
98
  s.require_paths = ["lib"]
95
99
  s.rubyforge_project = %q{rspec}
96
100
  s.rubygems_version = %q{1.3.6}
97
- s.summary = %q{rspec-rails-2.0.0.beta.5}
101
+ s.summary = %q{rspec-rails-2.0.0.beta.6}
98
102
  s.test_files = [
99
103
  "spec/rspec/rails/matchers/be_a_new_spec.rb",
100
104
  "spec/rspec/rails/matchers/redirect_to_spec.rb",
101
105
  "spec/rspec/rails/matchers/render_template_spec.rb",
106
+ "spec/rspec/rails/mocks/ar_classes.rb",
107
+ "spec/rspec/rails/mocks/mock_model_spec.rb",
108
+ "spec/rspec/rails/mocks/stub_model_spec.rb",
102
109
  "spec/rspec/rails/transactional_database_support_spec.rb",
103
110
  "spec/spec_helper.rb"
104
111
  ]
@@ -108,14 +115,14 @@ Gem::Specification.new do |s|
108
115
  s.specification_version = 3
109
116
 
110
117
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
111
- s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.5"])
118
+ s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.6"])
112
119
  s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
113
120
  else
114
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.5"])
121
+ s.add_dependency(%q<rspec>, ["= 2.0.0.beta.6"])
115
122
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
116
123
  end
117
124
  else
118
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.5"])
125
+ s.add_dependency(%q<rspec>, ["= 2.0.0.beta.6"])
119
126
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
120
127
  end
121
128
  end
@@ -0,0 +1,26 @@
1
+ module NoConnections
2
+ def self.included(mod)
3
+ (class << mod; self; end).class_eval do
4
+ def columns
5
+ []
6
+ end
7
+
8
+ def connection
9
+ Rspec::Mocks::Mock.new.as_null_object
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ class MockableModel < ActiveRecord::Base
16
+ include NoConnections
17
+ has_one :associated_model
18
+ end
19
+
20
+ class SubMockableModel < MockableModel
21
+ end
22
+
23
+ class AssociatedModel < ActiveRecord::Base
24
+ include NoConnections
25
+ belongs_to :mockable_model
26
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+ require File.dirname(__FILE__) + '/ar_classes'
3
+
4
+ describe "mock_model" do
5
+ describe "responding to interrogation" do
6
+ before(:each) do
7
+ @model = mock_model(SubMockableModel)
8
+ end
9
+ it "should say it is_a? if it is" do
10
+ @model.is_a?(SubMockableModel).should be(true)
11
+ end
12
+ it "should say it is_a? if it's ancestor is" do
13
+ @model.is_a?(MockableModel).should be(true)
14
+ end
15
+ it "should say it is kind_of? if it is" do
16
+ @model.kind_of?(SubMockableModel).should be(true)
17
+ end
18
+ it "should say it is kind_of? if it's ancestor is" do
19
+ @model.kind_of?(MockableModel).should be(true)
20
+ end
21
+ it "should say it is instance_of? if it is" do
22
+ @model.instance_of?(SubMockableModel).should be(true)
23
+ end
24
+ it "should not say it instance_of? if it isn't, even if it's ancestor is" do
25
+ @model.instance_of?(MockableModel).should be(false)
26
+ end
27
+ it "should say it is not destroyed" do
28
+ @model.destroyed?(SubMockableModel).should be(false)
29
+ end
30
+ it "should say it is not marked_for_destruction" do
31
+ @model.marked_for_destruction?.should be(false)
32
+ end
33
+ end
34
+
35
+ describe "with params" do
36
+ it "should not mutate its parameters" do
37
+ params = {:a => 'b'}
38
+ model = mock_model(MockableModel, params)
39
+ params.should == {:a => 'b'}
40
+ end
41
+ end
42
+
43
+ describe "with #id stubbed", :type => :view do
44
+ before(:each) do
45
+ @model = mock_model(MockableModel, :id => 1)
46
+ end
47
+ it "should be named using the stubbed id value" do
48
+ @model.instance_variable_get(:@name).should == "MockableModel_1"
49
+ end
50
+ it "should return string of id value for to_param" do
51
+ @model.to_param.should == "1"
52
+ end
53
+ end
54
+
55
+ describe "as association", :type => :view do
56
+ before(:each) do
57
+ @real = AssociatedModel.create!
58
+ @mock_model = mock_model(MockableModel)
59
+ @real.mockable_model = @mock_model
60
+ end
61
+
62
+ it "should pass associated_model == mock" do
63
+ @mock_model.should == @real.mockable_model
64
+ end
65
+
66
+ it "should pass mock == associated_model" do
67
+ @real.mockable_model.should == @mock_model
68
+ end
69
+ end
70
+
71
+ describe "with :null_object => true", :type => :view do
72
+ before(:each) do
73
+ @model = mock_model(MockableModel, :null_object => true, :mocked_method => "mocked")
74
+ end
75
+
76
+ it "should be able to mock methods" do
77
+ @model.mocked_method.should == "mocked"
78
+ end
79
+ it "should return itself to unmocked methods" do
80
+ @model.unmocked_method.should equal(@model)
81
+ end
82
+ end
83
+
84
+ describe "#as_null_object", :type => :view do
85
+ before(:each) do
86
+ @model = mock_model(MockableModel, :mocked_method => "mocked").as_null_object
87
+ end
88
+
89
+ it "should be able to mock methods" do
90
+ @model.mocked_method.should == "mocked"
91
+ end
92
+ it "should return itself to unmocked methods" do
93
+ @model.unmocked_method.should equal(@model)
94
+ end
95
+ end
96
+
97
+ describe "#as_new_record" do
98
+ it "should say it is a new record" do
99
+ m = mock_model(MockableModel)
100
+ m.as_new_record.should be_new_record
101
+ end
102
+
103
+ it "should have a nil id" do
104
+ mock_model(MockableModel).as_new_record.id.should be(nil)
105
+ end
106
+
107
+ it "should return nil for #to_param" do
108
+ mock_model(MockableModel).as_new_record.to_param.should be(nil)
109
+ end
110
+ end
111
+ end
112
+
113
+
114
+
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+ require File.dirname(__FILE__) + '/ar_classes'
3
+
4
+ describe "stub_model" do
5
+ describe "defaults" do
6
+ it "should have an id" do
7
+ stub_model(MockableModel).id.should be > 0
8
+ end
9
+
10
+ it "should say it is not a new record" do
11
+ stub_model(MockableModel).should_not be_new_record
12
+ end
13
+ end
14
+
15
+ it "should accept a stub id" do
16
+ stub_model(MockableModel, :id => 37).id.should == 37
17
+ end
18
+
19
+ it "should say it is a new record when id is set to nil" do
20
+ stub_model(MockableModel, :id => nil).should be_new_record
21
+ end
22
+
23
+ it "should accept any arbitrary stub" do
24
+ stub_model(MockableModel, :foo => "bar").foo.should == "bar"
25
+ end
26
+
27
+ it "should accept a stub for save" do
28
+ stub_model(MockableModel, :save => false).save.should be(false)
29
+ end
30
+
31
+ describe "#as_new_record" do
32
+ it "should say it is a new record" do
33
+ stub_model(MockableModel).as_new_record.should be_new_record
34
+ end
35
+
36
+ it "should have a nil id" do
37
+ stub_model(MockableModel).as_new_record.id.should be(nil)
38
+ end
39
+ end
40
+
41
+ pending "should raise when hitting the db" do
42
+ lambda do
43
+ model = stub_model(MockableModel, :changed => true, :attributes_with_quotes => {'this' => 'that'})
44
+ model.save
45
+ end.should raise_error(Rspec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
46
+ end
47
+
48
+ it "should increment the id" do
49
+ first = stub_model(MockableModel)
50
+ second = stub_model(MockableModel)
51
+ second.id.should == (first.id + 1)
52
+ end
53
+
54
+ describe "as association" do
55
+ before(:each) do
56
+ @real = AssociatedModel.create!
57
+ @stub_model = stub_model(MockableModel)
58
+ @real.mockable_model = @stub_model
59
+ end
60
+
61
+ it "should pass associated_model == mock" do
62
+ @stub_model.should == @real.mockable_model
63
+ end
64
+
65
+ it "should pass mock == associated_model" do
66
+ @real.mockable_model.should == @stub_model
67
+ end
68
+ end
69
+
70
+ describe "with a block" do
71
+ it "should yield the model" do
72
+ model = stub_model(MockableModel) do |block_arg|
73
+ @block_arg = block_arg
74
+ end
75
+ model.should be(@block_arg)
76
+ end
77
+ end
78
+ end
79
+
80
+
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 5
11
- version: 2.0.0.beta.5
10
+ - 6
11
+ version: 2.0.0.beta.6
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-04-04 00:00:00 -03:00
20
+ date: 2010-04-12 00:00:00 -05: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
- - 5
36
- version: 2.0.0.beta.5
35
+ - 6
36
+ version: 2.0.0.beta.6
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  - !ruby/object:Gem::Dependency
@@ -68,6 +68,7 @@ files:
68
68
  - features/model_specs/transactional_examples.feature
69
69
  - features/step_definitions/model_steps.rb
70
70
  - features/support/env.rb
71
+ - lib/autotest/rails_rspec2.rb
71
72
  - lib/generators/rspec.rb
72
73
  - lib/generators/rspec/controller/controller_generator.rb
73
74
  - lib/generators/rspec/controller/templates/controller_spec.rb
@@ -75,9 +76,9 @@ files:
75
76
  - lib/generators/rspec/helper/helper_generator.rb
76
77
  - lib/generators/rspec/helper/templates/helper_spec.rb
77
78
  - lib/generators/rspec/install/install_generator.rb
79
+ - lib/generators/rspec/install/templates/autotest/discover.rb
78
80
  - lib/generators/rspec/install/templates/config/initializers/rspec_generator.rb.tt
79
81
  - lib/generators/rspec/install/templates/lib/tasks/rspec.rake
80
- - lib/generators/rspec/install/templates/spec/spec.opts
81
82
  - lib/generators/rspec/install/templates/spec/spec_helper.rb
82
83
  - lib/generators/rspec/integration/integration_generator.rb
83
84
  - lib/generators/rspec/integration/templates/request_spec.rb
@@ -113,6 +114,9 @@ files:
113
114
  - spec/rspec/rails/matchers/be_a_new_spec.rb
114
115
  - spec/rspec/rails/matchers/redirect_to_spec.rb
115
116
  - spec/rspec/rails/matchers/render_template_spec.rb
117
+ - spec/rspec/rails/mocks/ar_classes.rb
118
+ - spec/rspec/rails/mocks/mock_model_spec.rb
119
+ - spec/rspec/rails/mocks/stub_model_spec.rb
116
120
  - spec/rspec/rails/transactional_database_support_spec.rb
117
121
  - spec/spec_helper.rb
118
122
  - specs.watchr
@@ -125,7 +129,7 @@ licenses: []
125
129
  post_install_message: |
126
130
  **************************************************
127
131
 
128
- Thank you for installing rspec-rails-2.0.0.beta.5!
132
+ Thank you for installing rspec-rails-2.0.0.beta.6!
129
133
 
130
134
  This version of rspec-rails only works with
131
135
  versions of rails >= 3.0.0.pre.
@@ -162,10 +166,13 @@ rubyforge_project: rspec
162
166
  rubygems_version: 1.3.6
163
167
  signing_key:
164
168
  specification_version: 3
165
- summary: rspec-rails-2.0.0.beta.5
169
+ summary: rspec-rails-2.0.0.beta.6
166
170
  test_files:
167
171
  - spec/rspec/rails/matchers/be_a_new_spec.rb
168
172
  - spec/rspec/rails/matchers/redirect_to_spec.rb
169
173
  - spec/rspec/rails/matchers/render_template_spec.rb
174
+ - spec/rspec/rails/mocks/ar_classes.rb
175
+ - spec/rspec/rails/mocks/mock_model_spec.rb
176
+ - spec/rspec/rails/mocks/stub_model_spec.rb
170
177
  - spec/rspec/rails/transactional_database_support_spec.rb
171
178
  - spec/spec_helper.rb
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress