rspec-rails 2.7.0.rc1 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -27
- data/lib/generators/rspec.rb +2 -2
- data/lib/rspec/rails/example/view_example_group.rb +10 -12
- data/lib/rspec/rails/extensions/active_record/base.rb +10 -8
- data/lib/rspec/rails/matchers/have_extension.rb +3 -3
- data/lib/rspec/rails/mocks.rb +14 -5
- data/lib/rspec/rails/version.rb +4 -4
- data/lib/rspec/rails/view_assigns.rb +4 -3
- metadata +22 -28
data/README.md
CHANGED
@@ -2,22 +2,7 @@
|
|
2
2
|
|
3
3
|
rspec-2 for rails-3 with lightweight extensions to each
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
NOTE: rspec-2 does _not_ support rails-2. Use rspec-rails-1.3.x for rails-2.
|
8
|
-
|
9
|
-
## Documentation
|
10
|
-
|
11
|
-
The [Cucumber features](http://relishapp.com/rspec/rspec-rails) are the
|
12
|
-
most comprehensive and up-to-date docs for end-users.
|
13
|
-
|
14
|
-
The [RDoc](http://rubydoc.info/gems/rspec-rails/2.4.0/frames) provides additional
|
15
|
-
information for contributors and/or extenders.
|
16
|
-
|
17
|
-
All of the documentation is open source and a work in progress. If you find it
|
18
|
-
lacking or confusing, you can help improve it by submitting requests and
|
19
|
-
patches to the [rspec-rails issue
|
20
|
-
tracker](https://github.com/rspec/rspec-rails/issues).
|
5
|
+
NOTE: Use rspec-rails-1.3.x for rails-2.
|
21
6
|
|
22
7
|
## Install
|
23
8
|
|
@@ -31,7 +16,7 @@ This installs the following gems:
|
|
31
16
|
rspec-mocks
|
32
17
|
rspec-rails
|
33
18
|
|
34
|
-
## Configure
|
19
|
+
## Configure
|
35
20
|
|
36
21
|
Add `rspec-rails` to the `:test` and `:development` groups in the Gemfile:
|
37
22
|
|
@@ -44,7 +29,7 @@ tasks without having to type `RAILS_ENV=test`.
|
|
44
29
|
|
45
30
|
Now you can run:
|
46
31
|
|
47
|
-
rails
|
32
|
+
rails generate rspec:install
|
48
33
|
|
49
34
|
This adds the spec directory and some skeleton files, including
|
50
35
|
the "rake spec" task.
|
@@ -56,17 +41,17 @@ see is `rspec:install`. That's because RSpec is registered with Rails as the
|
|
56
41
|
test framework, so whenever you generate application components like models,
|
57
42
|
controllers, etc, RSpec specs are generated instead of Test::Unit tests.
|
58
43
|
|
59
|
-
|
60
|
-
substitute for writing your own examples, and they are only guaranteed to
|
61
|
-
out of the box for the default scenario (`ActiveRecord` + `Webrat`).
|
44
|
+
Please note that the generators are there to help you get started, but they are
|
45
|
+
no substitute for writing your own examples, and they are only guaranteed to
|
46
|
+
work out of the box for the default scenario (`ActiveRecord` + `Webrat`).
|
62
47
|
|
63
48
|
### Autotest
|
64
49
|
|
65
|
-
The `rspec:install` generator creates an `.rspec` file, which
|
66
|
-
|
67
|
-
|
50
|
+
The `rspec:install` generator creates an `.rspec` file, which tells Autotest
|
51
|
+
that you're using RSpec and Rails. You'll also need to add the ZenTest gem to
|
52
|
+
your Gemfile:
|
68
53
|
|
69
|
-
gem "
|
54
|
+
gem "ZenTest"
|
70
55
|
|
71
56
|
At this point, if all of the gems in your Gemfile are installed in system
|
72
57
|
gems, you can just type `autotest`. If, however, Bundler is managing any gems
|
@@ -82,8 +67,6 @@ your preference to the Gemfile:
|
|
82
67
|
gem "webrat"
|
83
68
|
gem "capybara"
|
84
69
|
|
85
|
-
Note that Capybara matchers are not available in view or helper specs.
|
86
|
-
|
87
70
|
## Living on edge
|
88
71
|
|
89
72
|
Bundler makes it a snap to use the latest code for any gem your app depends on. For
|
data/lib/generators/rspec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rails/generators/named_base'
|
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
|
-
class Base < Rails::Generators::NamedBase
|
5
|
+
class Base < Rails::Generators::NamedBase
|
6
6
|
def self.source_root
|
7
7
|
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
8
8
|
end
|
@@ -12,7 +12,7 @@ end
|
|
12
12
|
|
13
13
|
module Rails
|
14
14
|
module Generators
|
15
|
-
class GeneratedAttribute
|
15
|
+
class GeneratedAttribute
|
16
16
|
def input_type
|
17
17
|
@input_type ||= if type == :text
|
18
18
|
"textarea"
|
@@ -40,14 +40,13 @@ module RSpec::Rails
|
|
40
40
|
end
|
41
41
|
|
42
42
|
module InstanceMethods
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# render({:partial => "widgets/widget.html.erb"}, {... locals ...}) do ... end
|
43
|
+
# @overload render
|
44
|
+
# @overload render({:partial => path_to_file})
|
45
|
+
# @overload render({:partial => path_to_file}, {... locals ...})
|
46
|
+
# @overload render({:partial => path_to_file}, {... locals ...}) do ... end
|
48
47
|
#
|
49
|
-
# Delegates to ActionView::Base#render, so see documentation on that
|
50
|
-
# info.
|
48
|
+
# Delegates to ActionView::Base#render, so see documentation on that
|
49
|
+
# for more info.
|
51
50
|
#
|
52
51
|
# The only addition is that you can call render with no arguments, and RSpec
|
53
52
|
# will pass the top level description to render:
|
@@ -63,9 +62,8 @@ module RSpec::Rails
|
|
63
62
|
super(options, local_assigns, &block)
|
64
63
|
end
|
65
64
|
|
66
|
-
# The instance of ActionView::Base that is used to render the template.
|
67
|
-
# Use this
|
68
|
-
# on the view:
|
65
|
+
# The instance of +ActionView::Base+ that is used to render the template.
|
66
|
+
# Use this to stub methods _before_ calling +render+.
|
69
67
|
#
|
70
68
|
# describe "widgets/new.html.erb" do
|
71
69
|
# it "shows all the widgets" do
|
@@ -98,13 +96,13 @@ module RSpec::Rails
|
|
98
96
|
controller.params
|
99
97
|
end
|
100
98
|
|
101
|
-
#
|
99
|
+
# @deprecated # use +view+ instead.
|
102
100
|
def template
|
103
101
|
RSpec.deprecate("template","view")
|
104
102
|
view
|
105
103
|
end
|
106
104
|
|
107
|
-
#
|
105
|
+
# @deprecated # use +rendered+ instead.
|
108
106
|
def response
|
109
107
|
RSpec.deprecate("response", "rendered")
|
110
108
|
rendered
|
@@ -3,19 +3,19 @@ module RSpec
|
|
3
3
|
if defined?(ActiveRecord)
|
4
4
|
module Extensions
|
5
5
|
module ActiveRecord
|
6
|
-
#
|
6
|
+
# Extension to enhance +should have+ on AR Model classes
|
7
|
+
#
|
8
|
+
# == Examples
|
7
9
|
# ModelClass.should have(:no).records
|
8
10
|
# ModelClass.should have(1).record
|
9
11
|
# ModelClass.should have(n).records
|
10
|
-
#
|
11
|
-
# Extension to enhance <tt>should have</tt> on AR Model classes
|
12
12
|
def records
|
13
13
|
find(:all)
|
14
14
|
end
|
15
15
|
alias :record :records
|
16
16
|
end
|
17
17
|
|
18
|
-
class ::ActiveRecord::Base
|
18
|
+
class ::ActiveRecord::Base
|
19
19
|
extend RSpec::Rails::Extensions::ActiveRecord
|
20
20
|
end
|
21
21
|
end
|
@@ -24,14 +24,16 @@ module RSpec
|
|
24
24
|
end
|
25
25
|
|
26
26
|
module ::ActiveModel::Validations
|
27
|
-
#
|
27
|
+
# Extension to enhance <tt>should have</tt> on AR Model instances.
|
28
|
+
# Calls model.valid? in order to prepare the object's errors
|
29
|
+
# object.
|
30
|
+
#
|
31
|
+
# == Examples
|
32
|
+
#
|
28
33
|
# model.should have(:no).errors_on(:attribute)
|
29
34
|
# model.should have(1).error_on(:attribute)
|
30
35
|
# model.should have(n).errors_on(:attribute)
|
31
36
|
#
|
32
|
-
# Extension to enhance <tt>should have</tt> on AR Model instances.
|
33
|
-
# Calls model.valid? in order to prepare the object's errors
|
34
|
-
# object.
|
35
37
|
def errors_on(attribute)
|
36
38
|
self.valid?
|
37
39
|
[self.errors[attribute]].flatten.compact
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'active_support/core_ext/module/aliasing'
|
2
2
|
require 'rspec/matchers/have'
|
3
3
|
|
4
|
-
module RSpec
|
5
|
-
module Matchers
|
6
|
-
class Have
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
class Have
|
7
7
|
def failure_message_for_should_with_errors_on_extensions
|
8
8
|
return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
|
9
9
|
return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
|
data/lib/rspec/rails/mocks.rb
CHANGED
@@ -9,31 +9,39 @@ module RSpec
|
|
9
9
|
module Mocks
|
10
10
|
|
11
11
|
module ActiveModelInstanceMethods
|
12
|
+
# Stubs +persisted?+ to return false and +id+ to return nil
|
13
|
+
# @return self
|
12
14
|
def as_new_record
|
13
15
|
self.stub(:persisted?) { false }
|
14
16
|
self.stub(:id) { nil }
|
15
17
|
self
|
16
18
|
end
|
17
19
|
|
20
|
+
# Returns true by default. Override with a stub.
|
18
21
|
def persisted?
|
19
22
|
true
|
20
23
|
end
|
21
24
|
|
25
|
+
# Returns false for names matching <tt>/_before_type_cast$/</tt>,
|
26
|
+
# otherwise delegates to super.
|
22
27
|
def respond_to?(message, include_private=false)
|
23
28
|
message.to_s =~ /_before_type_cast$/ ? false : super
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
32
|
module ActiveRecordInstanceMethods
|
33
|
+
# Stubs +persisted?+ to return +false+ and +id+ to return +nil+.
|
28
34
|
def destroy
|
29
35
|
self.stub(:persisted?) { false }
|
30
36
|
self.stub(:id) { nil }
|
31
37
|
end
|
32
38
|
|
39
|
+
# Transforms the key to a method and calls it.
|
33
40
|
def [](key)
|
34
41
|
send(key)
|
35
42
|
end
|
36
43
|
|
44
|
+
# Returns the opposite of +persisted?+
|
37
45
|
def new_record?
|
38
46
|
!persisted?
|
39
47
|
end
|
@@ -129,37 +137,38 @@ EOM
|
|
129
137
|
end
|
130
138
|
|
131
139
|
module ActiveModelStubExtensions
|
140
|
+
# Stubs +persisted+ to return false and +id+ to return nil
|
132
141
|
def as_new_record
|
133
142
|
self.stub(:persisted?) { false }
|
134
143
|
self.stub(:id) { nil }
|
135
144
|
self
|
136
145
|
end
|
137
146
|
|
147
|
+
# Returns +true+ by default. Override with a stub.
|
138
148
|
def persisted?
|
139
149
|
true
|
140
150
|
end
|
141
151
|
end
|
142
152
|
|
143
153
|
module ActiveRecordStubExtensions
|
154
|
+
# Stubs +id+ (or other primary key method) to return nil
|
144
155
|
def as_new_record
|
145
156
|
self.__send__("#{self.class.primary_key}=", nil)
|
146
157
|
super
|
147
158
|
end
|
148
159
|
|
160
|
+
# Returns the opposite of +persisted?+.
|
149
161
|
def new_record?
|
150
162
|
!persisted?
|
151
163
|
end
|
152
164
|
|
165
|
+
# Raises an IllegalDataAccessException (stubbed models are not allowed to access the database)
|
166
|
+
# @raises IllegalDataAccessException
|
153
167
|
def connection
|
154
168
|
raise RSpec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
|
155
169
|
end
|
156
170
|
end
|
157
171
|
|
158
|
-
# :call-seq:
|
159
|
-
# stub_model(Model)
|
160
|
-
# stub_model(Model).as_new_record
|
161
|
-
# stub_model(Model, hash_of_stubs)
|
162
|
-
#
|
163
172
|
# Creates an instance of +Model+ with +to_param+ stubbed using a
|
164
173
|
# generated value that is unique to each object.. If +Model+ is an
|
165
174
|
# +ActiveRecord+ model, it is prohibited from accessing the database*.
|
data/lib/rspec/rails/version.rb
CHANGED
@@ -4,11 +4,12 @@ module RSpec
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
module InstanceMethods
|
7
|
-
# :call-seq:
|
8
|
-
# assign(:widget, stub_model(Widget))
|
9
|
-
#
|
10
7
|
# Assigns a value to an instance variable in the scope of the
|
11
8
|
# view being rendered.
|
9
|
+
#
|
10
|
+
# == Examples
|
11
|
+
#
|
12
|
+
# assign(:widget, stub_model(Widget))
|
12
13
|
def assign(key, value)
|
13
14
|
_encapsulated_assigns[key] = value
|
14
15
|
end
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 7
|
9
9
|
- 0
|
10
|
-
|
11
|
-
- 1
|
12
|
-
version: 2.7.0.rc1
|
10
|
+
version: 2.7.0
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- David Chelimsky
|
@@ -17,12 +15,9 @@ autorequire:
|
|
17
15
|
bindir: bin
|
18
16
|
cert_chain: []
|
19
17
|
|
20
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-16 00:00:00 Z
|
21
19
|
dependencies:
|
22
20
|
- !ruby/object:Gem::Dependency
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
name: activesupport
|
26
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
27
22
|
none: false
|
28
23
|
requirements:
|
@@ -34,10 +29,10 @@ dependencies:
|
|
34
29
|
- 0
|
35
30
|
version: "3.0"
|
36
31
|
requirement: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
32
|
type: :runtime
|
39
33
|
prerelease: false
|
40
|
-
name:
|
34
|
+
name: activesupport
|
35
|
+
- !ruby/object:Gem::Dependency
|
41
36
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
37
|
none: false
|
43
38
|
requirements:
|
@@ -49,10 +44,10 @@ dependencies:
|
|
49
44
|
- 0
|
50
45
|
version: "3.0"
|
51
46
|
requirement: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
47
|
type: :runtime
|
54
48
|
prerelease: false
|
55
|
-
name:
|
49
|
+
name: actionpack
|
50
|
+
- !ruby/object:Gem::Dependency
|
56
51
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
52
|
none: false
|
58
53
|
requirements:
|
@@ -64,24 +59,25 @@ dependencies:
|
|
64
59
|
- 0
|
65
60
|
version: "3.0"
|
66
61
|
requirement: *id003
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
62
|
type: :runtime
|
69
63
|
prerelease: false
|
70
|
-
name:
|
64
|
+
name: railties
|
65
|
+
- !ruby/object:Gem::Dependency
|
71
66
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
67
|
none: false
|
73
68
|
requirements:
|
74
|
-
- -
|
69
|
+
- - ~>
|
75
70
|
- !ruby/object:Gem::Version
|
76
|
-
hash:
|
71
|
+
hash: 19
|
77
72
|
segments:
|
78
73
|
- 2
|
79
74
|
- 7
|
80
75
|
- 0
|
81
|
-
|
82
|
-
- 1
|
83
|
-
version: 2.7.0.rc1
|
76
|
+
version: 2.7.0
|
84
77
|
requirement: *id004
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
name: rspec
|
85
81
|
description: RSpec-2 for Rails-3
|
86
82
|
email: dchelimsky@gmail.com
|
87
83
|
executables: []
|
@@ -247,21 +243,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
247
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
248
244
|
none: false
|
249
245
|
requirements:
|
250
|
-
- - "
|
246
|
+
- - ">="
|
251
247
|
- !ruby/object:Gem::Version
|
252
|
-
hash:
|
248
|
+
hash: 3
|
253
249
|
segments:
|
254
|
-
-
|
255
|
-
|
256
|
-
- 1
|
257
|
-
version: 1.3.1
|
250
|
+
- 0
|
251
|
+
version: "0"
|
258
252
|
requirements: []
|
259
253
|
|
260
254
|
rubyforge_project: rspec
|
261
|
-
rubygems_version: 1.8.
|
255
|
+
rubygems_version: 1.8.11
|
262
256
|
signing_key:
|
263
257
|
specification_version: 3
|
264
|
-
summary: rspec-rails-2.7.0
|
258
|
+
summary: rspec-rails-2.7.0
|
265
259
|
test_files:
|
266
260
|
- features/Autotest.md
|
267
261
|
- features/Generators.md
|