cancan-unit-test 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.pairs +18 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +131 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +15 -0
- data/cancan_unit_test.gemspec +31 -0
- data/integration/controllers/mocks_spec.rb +25 -0
- data/integration/fixtures/dummy/README.rdoc +261 -0
- data/integration/fixtures/dummy/Rakefile +7 -0
- data/integration/fixtures/dummy/app/assets/javascripts/application.js +15 -0
- data/integration/fixtures/dummy/app/assets/stylesheets/application.css +13 -0
- data/integration/fixtures/dummy/app/controllers/application_controller.rb +7 -0
- data/integration/fixtures/dummy/app/controllers/posts_controller.rb +8 -0
- data/integration/fixtures/dummy/app/helpers/application_helper.rb +2 -0
- data/integration/fixtures/dummy/app/mailers/.gitkeep +0 -0
- data/integration/fixtures/dummy/app/models/.gitkeep +0 -0
- data/integration/fixtures/dummy/app/models/ability.rb +7 -0
- data/integration/fixtures/dummy/app/models/post.rb +3 -0
- data/integration/fixtures/dummy/app/views/layouts/application.html.erb +14 -0
- data/integration/fixtures/dummy/app/views/posts/index.erb +0 -0
- data/integration/fixtures/dummy/config.ru +4 -0
- data/integration/fixtures/dummy/config/application.rb +58 -0
- data/integration/fixtures/dummy/config/boot.rb +10 -0
- data/integration/fixtures/dummy/config/database.yml +25 -0
- data/integration/fixtures/dummy/config/environment.rb +5 -0
- data/integration/fixtures/dummy/config/environments/development.rb +37 -0
- data/integration/fixtures/dummy/config/environments/production.rb +67 -0
- data/integration/fixtures/dummy/config/environments/test.rb +37 -0
- data/integration/fixtures/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/integration/fixtures/dummy/config/initializers/inflections.rb +15 -0
- data/integration/fixtures/dummy/config/initializers/mime_types.rb +5 -0
- data/integration/fixtures/dummy/config/initializers/secret_token.rb +7 -0
- data/integration/fixtures/dummy/config/initializers/session_store.rb +8 -0
- data/integration/fixtures/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/integration/fixtures/dummy/config/locales/en.yml +5 -0
- data/integration/fixtures/dummy/config/routes.rb +61 -0
- data/integration/fixtures/dummy/db/development.sqlite3 +0 -0
- data/integration/fixtures/dummy/db/migrate/20130709143526_create_posts.rb +10 -0
- data/integration/fixtures/dummy/db/schema.rb +23 -0
- data/integration/fixtures/dummy/db/structure.sql +1 -0
- data/integration/fixtures/dummy/db/test.sqlite3 +0 -0
- data/integration/fixtures/dummy/lib/assets/.gitkeep +0 -0
- data/integration/fixtures/dummy/public/404.html +26 -0
- data/integration/fixtures/dummy/public/422.html +26 -0
- data/integration/fixtures/dummy/public/500.html +25 -0
- data/integration/fixtures/dummy/public/favicon.ico +0 -0
- data/integration/fixtures/dummy/script/rails +6 -0
- data/lib/cancan_unit_test.rb +11 -0
- data/lib/cancan_unit_test/action_controller/stub_registry.rb +28 -0
- data/lib/cancan_unit_test/action_controller_extensions.rb +1 -0
- data/lib/cancan_unit_test/cancan/controller_resource.rb +37 -0
- data/lib/cancan_unit_test/cancan_extensions.rb +1 -0
- data/lib/cancan_unit_test/mocks.rb +9 -0
- data/lib/cancan_unit_test/stub_finder.rb +30 -0
- data/lib/cancan_unit_test/version.rb +3 -0
- data/spec/cancan/controller_resource_spec.rb +115 -0
- data/spec/integration_helper.rb +36 -0
- data/spec/mocks_spec.rb +40 -0
- data/spec/rails/action_controller/stub_registry_spec.rb +98 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/stub_finder_spec.rb +60 -0
- metadata +241 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CancanUnitTest
|
4
|
+
module ActionController
|
5
|
+
|
6
|
+
describe StubRegistry do
|
7
|
+
|
8
|
+
class TestController
|
9
|
+
include CancanUnitTest::ActionController::StubRegistry
|
10
|
+
end
|
11
|
+
|
12
|
+
subject(:test_controller) { TestController.new }
|
13
|
+
|
14
|
+
let(:model) { :some_model }
|
15
|
+
let(:options) { double(:options) }
|
16
|
+
let(:block) { ->{} }
|
17
|
+
|
18
|
+
let(:expected_stub_definition) do
|
19
|
+
{
|
20
|
+
model: model,
|
21
|
+
options: options,
|
22
|
+
block: block
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "retrieving a stored stub definition" do
|
27
|
+
context "no stubs added" do
|
28
|
+
it "returns an empty array" do
|
29
|
+
test_controller._get_cancan_unit_test_stubs(:mango).should == []
|
30
|
+
end
|
31
|
+
|
32
|
+
it "does not raise an error" do
|
33
|
+
expect { test_controller._get_cancan_unit_test_stubs(:mango) }.not_to raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "added one stub" do
|
38
|
+
before do
|
39
|
+
test_controller._add_cancan_unit_test_stub(:falaffel, model, options, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be possible to find the stub with a matching key" do
|
43
|
+
test_controller._get_cancan_unit_test_stubs(:falaffel).should == [expected_stub_definition]
|
44
|
+
end
|
45
|
+
|
46
|
+
context "adding another with the same model name" do
|
47
|
+
let(:another_falaffel_model) { double(:model) }
|
48
|
+
let(:another_falaffel_stub_definition) do
|
49
|
+
{
|
50
|
+
model: another_falaffel_model,
|
51
|
+
options: options,
|
52
|
+
block: block
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
before do
|
57
|
+
test_controller._add_cancan_unit_test_stub(:falaffel, another_falaffel_model, options, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns both stubs" do
|
61
|
+
test_controller._get_cancan_unit_test_stubs(:falaffel).should ==
|
62
|
+
[expected_stub_definition,
|
63
|
+
another_falaffel_stub_definition]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "adding another with a different model name" do
|
68
|
+
let(:waffle_options) { { syrup: :maple } }
|
69
|
+
let(:waffle_stub_definition) do
|
70
|
+
{
|
71
|
+
model: model,
|
72
|
+
options: waffle_options,
|
73
|
+
block: block
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
before do
|
78
|
+
test_controller._add_cancan_unit_test_stub(:waffle, model, waffle_options, &block)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "return the other definition" do
|
82
|
+
test_controller._get_cancan_unit_test_stubs(:waffle).should ==
|
83
|
+
[waffle_stub_definition]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when the method has no definitions" do
|
88
|
+
it "returns an empty array" do
|
89
|
+
test_controller._get_cancan_unit_test_stubs(:gyro).should == []
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "pry"
|
3
|
+
require "rspec/mocks/extensions"
|
4
|
+
|
5
|
+
require "cancan_unit_test"
|
6
|
+
|
7
|
+
$:.unshift File.expand_path('..', __FILE__)
|
8
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
9
|
+
$:.unshift File.expand_path('../../integration', __FILE__)
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.color_enabled = true
|
13
|
+
config.before(:each) do
|
14
|
+
@lib_dir = File.expand_path('../../lib', __FILE__)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each { |f| require f }
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CancanUnitTest
|
4
|
+
describe StubFinder do
|
5
|
+
let_double(:controller)
|
6
|
+
let_double(:method)
|
7
|
+
let_double(:model)
|
8
|
+
let_double(:options)
|
9
|
+
let_double(:block)
|
10
|
+
|
11
|
+
let(:finder) { StubFinder.new(controller, method) }
|
12
|
+
|
13
|
+
describe "#find" do
|
14
|
+
subject { finder.find(model, options) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
controller.
|
18
|
+
stub(:_get_cancan_unit_test_stubs).
|
19
|
+
with(method).
|
20
|
+
and_return(results)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "the controller has no stubs" do
|
24
|
+
let(:results) { [] }
|
25
|
+
it { should be_nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "the controller has a stub for the method" do
|
29
|
+
context "with no matching model" do
|
30
|
+
let(:results) { [{ model: double(:other_model), options: options, block: block }] }
|
31
|
+
it { should be_nil }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with no matching options" do
|
35
|
+
let(:results) { [{ model: model, options: double(:other_options), block: block }] }
|
36
|
+
it { should be_nil }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with matching model and options" do
|
40
|
+
let(:results) { [{ model: model, options: options, block: block }] }
|
41
|
+
it { should == block }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "the controller has more than one matching stub" do
|
46
|
+
let(:results) do
|
47
|
+
[
|
48
|
+
{ model: model, options: options, block: block },
|
49
|
+
{ model: model, options: options, block: block }
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises an exception" do
|
54
|
+
expect { finder.find(model, options) }.to raise_error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cancan-unit-test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Todd Mohney, Rasheed Abdul-Aziz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cancan
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: railties
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec-mocks-extensions
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Unit test helpers for CanCan
|
140
|
+
email:
|
141
|
+
- zephyr-dev@googlegroups.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- .gitignore
|
147
|
+
- .pairs
|
148
|
+
- .rspec
|
149
|
+
- .travis.yml
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- cancan_unit_test.gemspec
|
156
|
+
- integration/controllers/mocks_spec.rb
|
157
|
+
- integration/fixtures/dummy/README.rdoc
|
158
|
+
- integration/fixtures/dummy/Rakefile
|
159
|
+
- integration/fixtures/dummy/app/assets/javascripts/application.js
|
160
|
+
- integration/fixtures/dummy/app/assets/stylesheets/application.css
|
161
|
+
- integration/fixtures/dummy/app/controllers/application_controller.rb
|
162
|
+
- integration/fixtures/dummy/app/controllers/posts_controller.rb
|
163
|
+
- integration/fixtures/dummy/app/helpers/application_helper.rb
|
164
|
+
- integration/fixtures/dummy/app/mailers/.gitkeep
|
165
|
+
- integration/fixtures/dummy/app/models/.gitkeep
|
166
|
+
- integration/fixtures/dummy/app/models/ability.rb
|
167
|
+
- integration/fixtures/dummy/app/models/post.rb
|
168
|
+
- integration/fixtures/dummy/app/views/layouts/application.html.erb
|
169
|
+
- integration/fixtures/dummy/app/views/posts/index.erb
|
170
|
+
- integration/fixtures/dummy/config.ru
|
171
|
+
- integration/fixtures/dummy/config/application.rb
|
172
|
+
- integration/fixtures/dummy/config/boot.rb
|
173
|
+
- integration/fixtures/dummy/config/database.yml
|
174
|
+
- integration/fixtures/dummy/config/environment.rb
|
175
|
+
- integration/fixtures/dummy/config/environments/development.rb
|
176
|
+
- integration/fixtures/dummy/config/environments/production.rb
|
177
|
+
- integration/fixtures/dummy/config/environments/test.rb
|
178
|
+
- integration/fixtures/dummy/config/initializers/backtrace_silencers.rb
|
179
|
+
- integration/fixtures/dummy/config/initializers/inflections.rb
|
180
|
+
- integration/fixtures/dummy/config/initializers/mime_types.rb
|
181
|
+
- integration/fixtures/dummy/config/initializers/secret_token.rb
|
182
|
+
- integration/fixtures/dummy/config/initializers/session_store.rb
|
183
|
+
- integration/fixtures/dummy/config/initializers/wrap_parameters.rb
|
184
|
+
- integration/fixtures/dummy/config/locales/en.yml
|
185
|
+
- integration/fixtures/dummy/config/routes.rb
|
186
|
+
- integration/fixtures/dummy/db/development.sqlite3
|
187
|
+
- integration/fixtures/dummy/db/migrate/20130709143526_create_posts.rb
|
188
|
+
- integration/fixtures/dummy/db/schema.rb
|
189
|
+
- integration/fixtures/dummy/db/structure.sql
|
190
|
+
- integration/fixtures/dummy/db/test.sqlite3
|
191
|
+
- integration/fixtures/dummy/lib/assets/.gitkeep
|
192
|
+
- integration/fixtures/dummy/log/.gitkeep
|
193
|
+
- integration/fixtures/dummy/public/404.html
|
194
|
+
- integration/fixtures/dummy/public/422.html
|
195
|
+
- integration/fixtures/dummy/public/500.html
|
196
|
+
- integration/fixtures/dummy/public/favicon.ico
|
197
|
+
- integration/fixtures/dummy/script/rails
|
198
|
+
- lib/cancan_unit_test.rb
|
199
|
+
- lib/cancan_unit_test/action_controller/stub_registry.rb
|
200
|
+
- lib/cancan_unit_test/action_controller_extensions.rb
|
201
|
+
- lib/cancan_unit_test/cancan/controller_resource.rb
|
202
|
+
- lib/cancan_unit_test/cancan_extensions.rb
|
203
|
+
- lib/cancan_unit_test/mocks.rb
|
204
|
+
- lib/cancan_unit_test/stub_finder.rb
|
205
|
+
- lib/cancan_unit_test/version.rb
|
206
|
+
- spec/cancan/controller_resource_spec.rb
|
207
|
+
- spec/integration_helper.rb
|
208
|
+
- spec/mocks_spec.rb
|
209
|
+
- spec/rails/action_controller/stub_registry_spec.rb
|
210
|
+
- spec/spec_helper.rb
|
211
|
+
- spec/stub_finder_spec.rb
|
212
|
+
homepage: ''
|
213
|
+
licenses: []
|
214
|
+
metadata: {}
|
215
|
+
post_install_message:
|
216
|
+
rdoc_options: []
|
217
|
+
require_paths:
|
218
|
+
- lib
|
219
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - '>='
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
224
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - '>='
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements: []
|
230
|
+
rubyforge_project:
|
231
|
+
rubygems_version: 2.0.3
|
232
|
+
signing_key:
|
233
|
+
specification_version: 4
|
234
|
+
summary: Unit test helpers for CanCan
|
235
|
+
test_files:
|
236
|
+
- spec/cancan/controller_resource_spec.rb
|
237
|
+
- spec/integration_helper.rb
|
238
|
+
- spec/mocks_spec.rb
|
239
|
+
- spec/rails/action_controller/stub_registry_spec.rb
|
240
|
+
- spec/spec_helper.rb
|
241
|
+
- spec/stub_finder_spec.rb
|