rspec-controller-matchers 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/.document +5 -0
- data/.rspec +2 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +175 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/rspec-controller-matchers.rb +1 -0
- data/lib/rspec/matchers/render_local_matcher.rb +59 -0
- data/rspec-controller-matchers.gemspec +64 -0
- data/spec/fixtures/views/test/index.html.erb +1 -0
- data/spec/fixtures/views/test/show.html.erb +1 -0
- data/spec/rspec/matchers/render_local_matcher_spec.rb +113 -0
- data/spec/spec_helper.rb +107 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 92b054074828fb3f2cad8abe30c60d1cdde7da4f
|
4
|
+
data.tar.gz: 33a4408d9ff26ebeceb9abb2e926d2c1aa9ce03b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63453875c78e763f57ae44a20f2bf78a927eefe392632b57ff99d920e531613cce9e046fed43c9019c35a810f848ec15e97c3a82c68353ca965ac431f34949cb
|
7
|
+
data.tar.gz: 74a99b4352fb4c95d5862e48c44c38ff804fd8d0b3396b3502486b2aa5510d8ceec9794b5411d52c92d381ebf6df299f3bb94f902ac04db8d7226ee045f9c21a
|
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "rails", ">= 4.2.6"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "juwelier", "~> 2.1.0"
|
13
|
+
gem "rspec-rails"
|
14
|
+
end
|
15
|
+
|
16
|
+
group "test" do
|
17
|
+
gem "pry-rails"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actioncable (5.1.0)
|
5
|
+
actionpack (= 5.1.0)
|
6
|
+
nio4r (~> 2.0)
|
7
|
+
websocket-driver (~> 0.6.1)
|
8
|
+
actionmailer (5.1.0)
|
9
|
+
actionpack (= 5.1.0)
|
10
|
+
actionview (= 5.1.0)
|
11
|
+
activejob (= 5.1.0)
|
12
|
+
mail (~> 2.5, >= 2.5.4)
|
13
|
+
rails-dom-testing (~> 2.0)
|
14
|
+
actionpack (5.1.0)
|
15
|
+
actionview (= 5.1.0)
|
16
|
+
activesupport (= 5.1.0)
|
17
|
+
rack (~> 2.0)
|
18
|
+
rack-test (~> 0.6.3)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
21
|
+
actionview (5.1.0)
|
22
|
+
activesupport (= 5.1.0)
|
23
|
+
builder (~> 3.1)
|
24
|
+
erubi (~> 1.4)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
27
|
+
activejob (5.1.0)
|
28
|
+
activesupport (= 5.1.0)
|
29
|
+
globalid (>= 0.3.6)
|
30
|
+
activemodel (5.1.0)
|
31
|
+
activesupport (= 5.1.0)
|
32
|
+
activerecord (5.1.0)
|
33
|
+
activemodel (= 5.1.0)
|
34
|
+
activesupport (= 5.1.0)
|
35
|
+
arel (~> 8.0)
|
36
|
+
activesupport (5.1.0)
|
37
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
38
|
+
i18n (~> 0.7)
|
39
|
+
minitest (~> 5.1)
|
40
|
+
tzinfo (~> 1.1)
|
41
|
+
addressable (2.4.0)
|
42
|
+
arel (8.0.0)
|
43
|
+
builder (3.2.3)
|
44
|
+
coderay (1.1.1)
|
45
|
+
concurrent-ruby (1.0.5)
|
46
|
+
descendants_tracker (0.0.4)
|
47
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
48
|
+
diff-lcs (1.3)
|
49
|
+
erubi (1.6.0)
|
50
|
+
faraday (0.9.2)
|
51
|
+
multipart-post (>= 1.2, < 3)
|
52
|
+
git (1.3.0)
|
53
|
+
github_api (0.17.0)
|
54
|
+
addressable (~> 2.4.0)
|
55
|
+
descendants_tracker (~> 0.0.4)
|
56
|
+
faraday (~> 0.8, < 0.10)
|
57
|
+
hashie (>= 3.4)
|
58
|
+
mime-types (>= 1.16, < 3.0)
|
59
|
+
oauth2 (~> 1.0)
|
60
|
+
globalid (0.4.0)
|
61
|
+
activesupport (>= 4.2.0)
|
62
|
+
hashie (3.5.5)
|
63
|
+
highline (1.7.8)
|
64
|
+
i18n (0.8.1)
|
65
|
+
juwelier (2.1.3)
|
66
|
+
builder
|
67
|
+
bundler (>= 1.13)
|
68
|
+
git (>= 1.2.5)
|
69
|
+
github_api
|
70
|
+
highline (>= 1.6.15)
|
71
|
+
nokogiri (>= 1.5.10)
|
72
|
+
rake
|
73
|
+
rdoc
|
74
|
+
semver
|
75
|
+
jwt (1.5.6)
|
76
|
+
loofah (2.0.3)
|
77
|
+
nokogiri (>= 1.5.9)
|
78
|
+
mail (2.6.5)
|
79
|
+
mime-types (>= 1.16, < 4)
|
80
|
+
method_source (0.8.2)
|
81
|
+
mime-types (2.99.3)
|
82
|
+
mini_portile2 (2.1.0)
|
83
|
+
minitest (5.10.1)
|
84
|
+
multi_json (1.12.1)
|
85
|
+
multi_xml (0.6.0)
|
86
|
+
multipart-post (2.0.0)
|
87
|
+
nio4r (2.0.0)
|
88
|
+
nokogiri (1.7.1)
|
89
|
+
mini_portile2 (~> 2.1.0)
|
90
|
+
oauth2 (1.3.1)
|
91
|
+
faraday (>= 0.8, < 0.12)
|
92
|
+
jwt (~> 1.0)
|
93
|
+
multi_json (~> 1.3)
|
94
|
+
multi_xml (~> 0.5)
|
95
|
+
rack (>= 1.2, < 3)
|
96
|
+
pry (0.10.4)
|
97
|
+
coderay (~> 1.1.0)
|
98
|
+
method_source (~> 0.8.1)
|
99
|
+
slop (~> 3.4)
|
100
|
+
pry-rails (0.3.6)
|
101
|
+
pry (>= 0.10.4)
|
102
|
+
rack (2.0.1)
|
103
|
+
rack-test (0.6.3)
|
104
|
+
rack (>= 1.0)
|
105
|
+
rails (5.1.0)
|
106
|
+
actioncable (= 5.1.0)
|
107
|
+
actionmailer (= 5.1.0)
|
108
|
+
actionpack (= 5.1.0)
|
109
|
+
actionview (= 5.1.0)
|
110
|
+
activejob (= 5.1.0)
|
111
|
+
activemodel (= 5.1.0)
|
112
|
+
activerecord (= 5.1.0)
|
113
|
+
activesupport (= 5.1.0)
|
114
|
+
bundler (>= 1.3.0, < 2.0)
|
115
|
+
railties (= 5.1.0)
|
116
|
+
sprockets-rails (>= 2.0.0)
|
117
|
+
rails-dom-testing (2.0.2)
|
118
|
+
activesupport (>= 4.2.0, < 6.0)
|
119
|
+
nokogiri (~> 1.6)
|
120
|
+
rails-html-sanitizer (1.0.3)
|
121
|
+
loofah (~> 2.0)
|
122
|
+
railties (5.1.0)
|
123
|
+
actionpack (= 5.1.0)
|
124
|
+
activesupport (= 5.1.0)
|
125
|
+
method_source
|
126
|
+
rake (>= 0.8.7)
|
127
|
+
thor (>= 0.18.1, < 2.0)
|
128
|
+
rake (12.0.0)
|
129
|
+
rdoc (5.1.0)
|
130
|
+
rspec-core (3.6.0)
|
131
|
+
rspec-support (~> 3.6.0)
|
132
|
+
rspec-expectations (3.6.0)
|
133
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
134
|
+
rspec-support (~> 3.6.0)
|
135
|
+
rspec-mocks (3.6.0)
|
136
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
137
|
+
rspec-support (~> 3.6.0)
|
138
|
+
rspec-rails (3.6.0)
|
139
|
+
actionpack (>= 3.0)
|
140
|
+
activesupport (>= 3.0)
|
141
|
+
railties (>= 3.0)
|
142
|
+
rspec-core (~> 3.6.0)
|
143
|
+
rspec-expectations (~> 3.6.0)
|
144
|
+
rspec-mocks (~> 3.6.0)
|
145
|
+
rspec-support (~> 3.6.0)
|
146
|
+
rspec-support (3.6.0)
|
147
|
+
semver (1.0.1)
|
148
|
+
slop (3.6.0)
|
149
|
+
sprockets (3.7.1)
|
150
|
+
concurrent-ruby (~> 1.0)
|
151
|
+
rack (> 1, < 3)
|
152
|
+
sprockets-rails (3.2.0)
|
153
|
+
actionpack (>= 4.0)
|
154
|
+
activesupport (>= 4.0)
|
155
|
+
sprockets (>= 3.0.0)
|
156
|
+
thor (0.19.4)
|
157
|
+
thread_safe (0.3.6)
|
158
|
+
tzinfo (1.2.3)
|
159
|
+
thread_safe (~> 0.1)
|
160
|
+
websocket-driver (0.6.5)
|
161
|
+
websocket-extensions (>= 0.1.0)
|
162
|
+
websocket-extensions (0.1.2)
|
163
|
+
|
164
|
+
PLATFORMS
|
165
|
+
ruby
|
166
|
+
|
167
|
+
DEPENDENCIES
|
168
|
+
bundler (~> 1.0)
|
169
|
+
juwelier (~> 2.1.0)
|
170
|
+
pry-rails
|
171
|
+
rails (>= 4.2.6)
|
172
|
+
rspec-rails
|
173
|
+
|
174
|
+
BUNDLED WITH
|
175
|
+
1.14.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2017 Stevo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
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 BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= rspec-controller-matchers
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to rspec-controller-matchers
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2017 Stevo. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'juwelier'
|
15
|
+
Juwelier::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "rspec-controller-matchers"
|
18
|
+
gem.homepage = "http://github.com/selleo/rspec-controller-matchers"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Facilitate assertions for common controller responsibilites"
|
21
|
+
gem.description = "Facilitate assertions for common controller responsibilites"
|
22
|
+
gem.email = "blazejek@gmail.com"
|
23
|
+
gem.authors = ["Stevo"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Juwelier::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "rspec-controller-matchers #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1 @@
|
|
1
|
+
require "rspec/matchers/render_local_matcher"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
RSpec::Matchers.define :render_local do |*args|
|
2
|
+
match do |actual|
|
3
|
+
allow(controller).to receive(:render).and_call_original
|
4
|
+
|
5
|
+
set_expected_key_and_value(*args)
|
6
|
+
|
7
|
+
if @intermediate_klass
|
8
|
+
allow(@intermediate_klass).to receive(:call) { @value }
|
9
|
+
end
|
10
|
+
|
11
|
+
actual.call
|
12
|
+
|
13
|
+
verify_local!
|
14
|
+
end
|
15
|
+
|
16
|
+
def using(klass)
|
17
|
+
@intermediate_klass = klass
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
supports_block_expectations
|
22
|
+
|
23
|
+
def set_expected_key_and_value(*args)
|
24
|
+
locals_hash = args.extract_options!
|
25
|
+
|
26
|
+
@key = nil
|
27
|
+
@value = nil
|
28
|
+
|
29
|
+
if locals_hash.present?
|
30
|
+
@key = locals_hash.keys.first.to_sym
|
31
|
+
@value = locals_hash.values.first
|
32
|
+
elsif args.size == 2
|
33
|
+
@key = args.first.to_sym
|
34
|
+
subject = args.pop
|
35
|
+
if subject.is_a?(Class)
|
36
|
+
@value = kind_of(subject)
|
37
|
+
else
|
38
|
+
@value = subject
|
39
|
+
end
|
40
|
+
elsif args.size == 1
|
41
|
+
subject = args.pop
|
42
|
+
if subject.is_a?(Class)
|
43
|
+
@key = subject.name.underscore.to_sym
|
44
|
+
@value = kind_of(subject)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def verify_local!
|
50
|
+
if @intermediate_klass
|
51
|
+
expect(@intermediate_klass).to have_received(:call)
|
52
|
+
end
|
53
|
+
expect(controller).to have_received(:render).
|
54
|
+
at_least(:once).
|
55
|
+
with(anything, hash_including(locals: hash_including(@key => @value)))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by juwelier
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: rspec-controller-matchers 0.0.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rspec-controller-matchers".freeze
|
9
|
+
s.version = "0.0.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Stevo".freeze]
|
14
|
+
s.date = "2017-05-08"
|
15
|
+
s.description = "Facilitate assertions for common controller responsibilites".freeze
|
16
|
+
s.email = "blazejek@gmail.com".freeze
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"lib/rspec-controller-matchers.rb",
|
31
|
+
"lib/rspec/matchers/render_local_matcher.rb",
|
32
|
+
"rspec-controller-matchers.gemspec",
|
33
|
+
"spec/fixtures/views/test/index.html.erb",
|
34
|
+
"spec/fixtures/views/test/show.html.erb",
|
35
|
+
"spec/rspec/matchers/render_local_matcher_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/selleo/rspec-controller-matchers".freeze
|
39
|
+
s.licenses = ["MIT".freeze]
|
40
|
+
s.rubygems_version = "2.6.10".freeze
|
41
|
+
s.summary = "Facilitate assertions for common controller responsibilites".freeze
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 4
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<rails>.freeze, [">= 4.2.6"])
|
48
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
49
|
+
s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
50
|
+
s.add_development_dependency(%q<rspec-rails>.freeze, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rails>.freeze, [">= 4.2.6"])
|
53
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
54
|
+
s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
55
|
+
s.add_dependency(%q<rspec-rails>.freeze, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rails>.freeze, [">= 4.2.6"])
|
59
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
60
|
+
s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
61
|
+
s.add_dependency(%q<rspec-rails>.freeze, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
require 'action_controller'
|
5
|
+
require 'rails'
|
6
|
+
require 'rspec/rails'
|
7
|
+
|
8
|
+
module Test
|
9
|
+
class TestApplication < ::Rails::Application
|
10
|
+
end
|
11
|
+
TestApplication.config.secret_key_base = 'test'
|
12
|
+
end
|
13
|
+
|
14
|
+
class TestController < ActionController::Base
|
15
|
+
end
|
16
|
+
|
17
|
+
describe TestController, type: :controller do
|
18
|
+
context "controller render local with simple value" do
|
19
|
+
controller(TestController) do
|
20
|
+
append_view_path("spec/fixtures/views")
|
21
|
+
|
22
|
+
def index
|
23
|
+
render :index, locals: { example_local_name: 10 }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "ensures that a local with given value was passed to render" do
|
28
|
+
expect { get :index }.to render_local(example_local_name: 10)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "ensures that a local with given value was not passed to render" do
|
32
|
+
expect { get :index }.to_not render_local(example_local_name: 11)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "controller render local with object of given class" do
|
37
|
+
controller(TestController) do
|
38
|
+
append_view_path("spec/fixtures/views")
|
39
|
+
|
40
|
+
class DummyClass; end
|
41
|
+
class AnotherDummyClass; end
|
42
|
+
|
43
|
+
def index
|
44
|
+
render :index, locals: { example_local_name: DummyClass.new }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "ensures that a local with given object was passed to render" do
|
49
|
+
expect { get :index }.to render_local(:example_local_name, DummyClass)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "ensures that a local with given object as not passed to render" do
|
53
|
+
expect { get :index }.to_not render_local(:example_local_name, AnotherDummyClass)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "local name matches snake-cased klass name" do
|
57
|
+
controller(TestController) do
|
58
|
+
append_view_path("spec/fixtures/views")
|
59
|
+
|
60
|
+
class DummyClass; end
|
61
|
+
class AnotherDummyClass; end
|
62
|
+
|
63
|
+
def index
|
64
|
+
render :index, locals: { dummy_class: DummyClass.new }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "ensures that a local with given object was passed to render" do
|
69
|
+
expect { get :index }.to render_local(DummyClass)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "ensures that a local with given object as not passed to render" do
|
73
|
+
expect { get :index }.to_not render_local(AnotherDummyClass)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "local name does not match snake-cased klass name" do
|
78
|
+
controller(TestController) do
|
79
|
+
append_view_path("spec/fixtures/views")
|
80
|
+
|
81
|
+
class DummyClass; end
|
82
|
+
|
83
|
+
def index
|
84
|
+
render :index, locals: { dummy_nice_class: DummyClass.new }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "ensures that a local with given object was passed to render" do
|
89
|
+
expect { get :index }.to_not render_local(DummyClass)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "ensuring origin of local" do
|
94
|
+
controller(TestController) do
|
95
|
+
append_view_path("spec/fixtures/views")
|
96
|
+
|
97
|
+
class DummyQuery
|
98
|
+
def self.call
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def index
|
104
|
+
render :index, locals: { locations: DummyQuery.call }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "ensures local hash value been retrieved from service-like object" do
|
109
|
+
expect { get :index }.to render_local(:locations, [1, 2, 3]).using(DummyQuery)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
|
20
|
+
require "pry"
|
21
|
+
require "rspec-controller-matchers"
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
# rspec-expectations config goes here. You can use an alternate
|
25
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
26
|
+
# assertions if you prefer.
|
27
|
+
config.expect_with :rspec do |expectations|
|
28
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
29
|
+
# and `failure_message` of custom matchers include text for helper methods
|
30
|
+
# defined using `chain`, e.g.:
|
31
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
32
|
+
# # => "be bigger than 2 and smaller than 4"
|
33
|
+
# ...rather than:
|
34
|
+
# # => "be bigger than 2"
|
35
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
36
|
+
end
|
37
|
+
|
38
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
39
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
40
|
+
config.mock_with :rspec do |mocks|
|
41
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
42
|
+
# a real object. This is generally recommended, and will default to
|
43
|
+
# `true` in RSpec 4.
|
44
|
+
mocks.verify_partial_doubles = true
|
45
|
+
end
|
46
|
+
|
47
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
48
|
+
# have no way to turn it off -- the option exists only for backwards
|
49
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
50
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
51
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
52
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
53
|
+
|
54
|
+
# The settings below are suggested to provide a good initial experience
|
55
|
+
# with RSpec, but feel free to customize to your heart's content.
|
56
|
+
=begin
|
57
|
+
# This allows you to limit a spec run to individual examples or groups
|
58
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
59
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
60
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
61
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
62
|
+
config.filter_run_when_matching :focus
|
63
|
+
|
64
|
+
# Allows RSpec to persist some state between runs in order to support
|
65
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
66
|
+
# you configure your source control system to ignore this file.
|
67
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
68
|
+
|
69
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
70
|
+
# recommended. For more details, see:
|
71
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
72
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
73
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
74
|
+
config.disable_monkey_patching!
|
75
|
+
|
76
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
77
|
+
# be too noisy due to issues in dependencies.
|
78
|
+
config.warnings = true
|
79
|
+
|
80
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
81
|
+
# file, and it's useful to allow more verbose output when running an
|
82
|
+
# individual spec file.
|
83
|
+
if config.files_to_run.one?
|
84
|
+
# Use the documentation formatter for detailed output,
|
85
|
+
# unless a formatter has already been configured
|
86
|
+
# (e.g. via a command-line flag).
|
87
|
+
config.default_formatter = 'doc'
|
88
|
+
end
|
89
|
+
|
90
|
+
# Print the 10 slowest examples and example groups at the
|
91
|
+
# end of the spec run, to help surface which specs are running
|
92
|
+
# particularly slow.
|
93
|
+
config.profile_examples = 10
|
94
|
+
|
95
|
+
# Run specs in random order to surface order dependencies. If you find an
|
96
|
+
# order dependency and want to debug it, you can fix the order by providing
|
97
|
+
# the seed, which is printed after each run.
|
98
|
+
# --seed 1234
|
99
|
+
config.order = :random
|
100
|
+
|
101
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
102
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
103
|
+
# test failures related to randomization by passing the same `--seed` value
|
104
|
+
# as the one that triggered the failure.
|
105
|
+
Kernel.srand config.seed
|
106
|
+
=end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-controller-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stevo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: juwelier
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
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
|
+
description: Facilitate assertions for common controller responsibilites
|
70
|
+
email: blazejek@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.rdoc
|
76
|
+
files:
|
77
|
+
- ".document"
|
78
|
+
- ".rspec"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.rdoc
|
83
|
+
- Rakefile
|
84
|
+
- VERSION
|
85
|
+
- lib/rspec-controller-matchers.rb
|
86
|
+
- lib/rspec/matchers/render_local_matcher.rb
|
87
|
+
- rspec-controller-matchers.gemspec
|
88
|
+
- spec/fixtures/views/test/index.html.erb
|
89
|
+
- spec/fixtures/views/test/show.html.erb
|
90
|
+
- spec/rspec/matchers/render_local_matcher_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: http://github.com/selleo/rspec-controller-matchers
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.6.10
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Facilitate assertions for common controller responsibilites
|
116
|
+
test_files: []
|