keyword_parameter_matchers 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +14 -0
- data/keyword_parameter_matchers.gemspec +24 -0
- data/lib/keyword_parameter_matchers/have_keyword_parameter.rb +42 -0
- data/lib/keyword_parameter_matchers/have_optional_keyword_parameter.rb +43 -0
- data/lib/keyword_parameter_matchers/have_required_keyword_parameter.rb +43 -0
- data/lib/keyword_parameter_matchers/matcher_helpers.rb +15 -0
- data/lib/keyword_parameter_matchers/null_method.rb +19 -0
- data/lib/keyword_parameter_matchers/rspec.rb +7 -0
- data/lib/keyword_parameter_matchers/version.rb +3 -0
- data/lib/keyword_parameter_matchers.rb +9 -0
- data/spec/keyword_parameter_matchers/have_keyword_parameter_spec.rb +69 -0
- data/spec/keyword_parameter_matchers/have_optional_keyword_parameter_spec.rb +69 -0
- data/spec/keyword_parameter_matchers/have_required_keyword_parameter_spec.rb +69 -0
- data/spec/keyword_parameter_matchers/matcher_helpers_spec.rb +75 -0
- data/spec/keyword_parameter_matchers/null_method_spec.rb +41 -0
- data/spec/spec_helper.rb +13 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1e7eed87ee5faa88979a1e9d1d9fb08fc5aca766
|
4
|
+
data.tar.gz: b8ee3bc2911591af7e61c4647b177fad1a83d91e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4366510b9c32879c407a92fba1ebe2ef31520ff461ac8361c440aa16749bb04fadde5f10ce91de355ec01d0f3df1949e6b7e4c750c53a96bb06e3bb1b5f8c7d6
|
7
|
+
data.tar.gz: b9959c0f05025fefaf5d28b38e551dce5cdfc1f20baf72832757f82f30610b0fdbdc43431ce6023ad81661968cfaa2d993c8bfee002e6b56ed92272f704194b6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Terry Finn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Keyword Parameter Matchers
|
2
|
+
|
3
|
+
Simple matchers for method keyword parameters.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'keyword_parameter_matchers'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
```shell
|
15
|
+
$ bundle
|
16
|
+
```
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
```shell
|
20
|
+
$ gem install keyword_parameter_matchers
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'keyword_parameter_matchers/rspec'
|
27
|
+
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'keyword_parameter_matchers/rspec'
|
35
|
+
|
36
|
+
class Example
|
37
|
+
def self.example_class_method(a:, b: 'B')
|
38
|
+
end
|
39
|
+
|
40
|
+
def example_instance_method(a:, b: 'B')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Example
|
45
|
+
describe '.example_class_method' do
|
46
|
+
it 'requies keyword a' do
|
47
|
+
expect(
|
48
|
+
Example.method(:example_class_method)
|
49
|
+
).to have_required_keyword(:a)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'has optional keyword b' do
|
53
|
+
expect(
|
54
|
+
Example.method(:example_class_method)
|
55
|
+
).to have_optional_keyword(:b)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#example_instance_method' do
|
60
|
+
it 'requies keyword a' do
|
61
|
+
expect(
|
62
|
+
Example.instance_method(:example_instance_method)
|
63
|
+
).to have_required_keyword(:a)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'has optional keyword b' do
|
67
|
+
expect(
|
68
|
+
Example.instance_method(:example_instance_method)
|
69
|
+
).to have_optional_keyword(:b)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it ( https://github.com/terryfinn/keyword_parameter_matchers/fork )
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task default: :spec
|
7
|
+
|
8
|
+
desc 'Start a PRY session with KeywordParameterMatchers loaded'
|
9
|
+
task :console do
|
10
|
+
require 'pry'
|
11
|
+
require 'keyword_parameter_matchers'
|
12
|
+
ARGV.clear
|
13
|
+
Pry.start
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'keyword_parameter_matchers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'keyword_parameter_matchers'
|
8
|
+
spec.version = KeywordParameterMatchers::VERSION
|
9
|
+
spec.authors = ['Terry Finn']
|
10
|
+
spec.email = ['terry@terryrfinn.com']
|
11
|
+
spec.summary = %q{Simple matchers for method keyword parameters.}
|
12
|
+
spec.homepage = 'https://github.com/terryfinn/keyword_parameter_matchers'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
21
|
+
spec.add_development_dependency 'pry-byebug'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module KeywordParameterMatchers
|
2
|
+
class HaveKeywordParameter
|
3
|
+
def initialize(expected)
|
4
|
+
@expected = expected
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(actual)
|
8
|
+
@actual = actual
|
9
|
+
|
10
|
+
actual.parameters.any? { |type, name|
|
11
|
+
[:key, :keyreq].include?(type) && name == @expected
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message
|
16
|
+
"expected \"#{expected}\" to a keyword parameter in #{method_name} " \
|
17
|
+
"parameter list #{parameter_list.inspect}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_when_negated
|
21
|
+
"expected \"#{expected}\" not to a keyword parameter in #{method_name} " \
|
22
|
+
"parameter list #{parameter_list.inspect}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def actual
|
27
|
+
NullMethod.new_if_nil(@actual)
|
28
|
+
end
|
29
|
+
|
30
|
+
def expected
|
31
|
+
@expected
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_name
|
35
|
+
actual.name
|
36
|
+
end
|
37
|
+
|
38
|
+
def parameter_list
|
39
|
+
actual.parameters
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module KeywordParameterMatchers
|
2
|
+
class HaveOptionalKeywordParameter
|
3
|
+
def initialize(expected)
|
4
|
+
@expected = expected
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(actual)
|
8
|
+
@actual = actual
|
9
|
+
|
10
|
+
actual.parameters.any? { |type, name|
|
11
|
+
:key == type && name == expected
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message
|
16
|
+
"expected \"#{expected}\" to be a optional keyword parameter in " \
|
17
|
+
"example_method parameter list #{parameter_list.inspect}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_when_negated
|
21
|
+
"expected \"#{expected}\" not to be an optional keyword " \
|
22
|
+
"parameter in example_method parameter list " \
|
23
|
+
"#{parameter_list.inspect}"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def actual
|
28
|
+
NullMethod.new_if_nil(@actual)
|
29
|
+
end
|
30
|
+
|
31
|
+
def expected
|
32
|
+
@expected
|
33
|
+
end
|
34
|
+
|
35
|
+
def method_name
|
36
|
+
actual.name
|
37
|
+
end
|
38
|
+
|
39
|
+
def parameter_list
|
40
|
+
actual.parameters
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module KeywordParameterMatchers
|
2
|
+
class HaveRequiredKeywordParameter
|
3
|
+
def initialize(expected)
|
4
|
+
@expected = expected
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(actual)
|
8
|
+
@actual = actual
|
9
|
+
|
10
|
+
actual.parameters.any? { |type, name|
|
11
|
+
:keyreq == type && name == expected
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message
|
16
|
+
"expected \"#{expected}\" to be a required keyword parameter in " \
|
17
|
+
"example_method parameter list #{parameter_list.inspect}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_when_negated
|
21
|
+
"expected \"#{expected}\" not to be an required keyword " \
|
22
|
+
"parameter in example_method parameter list " \
|
23
|
+
"#{parameter_list.inspect}"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def actual
|
28
|
+
NullMethod.new_if_nil(@actual)
|
29
|
+
end
|
30
|
+
|
31
|
+
def expected
|
32
|
+
@expected
|
33
|
+
end
|
34
|
+
|
35
|
+
def method_name
|
36
|
+
actual.name
|
37
|
+
end
|
38
|
+
|
39
|
+
def parameter_list
|
40
|
+
actual.parameters
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module KeywordParameterMatchers
|
2
|
+
module MatcherHelpers
|
3
|
+
def have_keyword_parameter(expected)
|
4
|
+
HaveKeywordParameter.new(expected)
|
5
|
+
end
|
6
|
+
|
7
|
+
def have_optional_keyword_parameter(expected)
|
8
|
+
HaveOptionalKeywordParameter.new(expected)
|
9
|
+
end
|
10
|
+
|
11
|
+
def have_required_keyword_parameter(expected)
|
12
|
+
HaveRequiredKeywordParameter.new(expected)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'keyword_parameter_matchers/have_keyword_parameter'
|
2
|
+
require 'keyword_parameter_matchers/have_optional_keyword_parameter'
|
3
|
+
require 'keyword_parameter_matchers/have_required_keyword_parameter'
|
4
|
+
require 'keyword_parameter_matchers/matcher_helpers'
|
5
|
+
require 'keyword_parameter_matchers/null_method'
|
6
|
+
require 'keyword_parameter_matchers/version'
|
7
|
+
|
8
|
+
module KeywordParameterMatchers
|
9
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KeywordParameterMatchers::HaveKeywordParameter do
|
4
|
+
describe '#matches?' do
|
5
|
+
it 'returns true when the keyword is a method parameter' do
|
6
|
+
method = instance_double(Method)
|
7
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
8
|
+
matcher = KeywordParameterMatchers::HaveKeywordParameter.new(
|
9
|
+
:a
|
10
|
+
)
|
11
|
+
|
12
|
+
expect(
|
13
|
+
matcher.matches?(method)
|
14
|
+
).to eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false when the keyword is not a method parameter' do
|
18
|
+
method = instance_double(Method)
|
19
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
20
|
+
matcher = KeywordParameterMatchers::HaveKeywordParameter.new(
|
21
|
+
:b
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(
|
25
|
+
matcher.matches?(method)
|
26
|
+
).to eq(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#failure_message' do
|
31
|
+
it 'says the keyword is not a method parameter' do
|
32
|
+
method = instance_double(Method)
|
33
|
+
allow(method).to receive(:name).and_return(:example_method)
|
34
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
35
|
+
matcher = KeywordParameterMatchers::HaveKeywordParameter.new(
|
36
|
+
:b
|
37
|
+
)
|
38
|
+
|
39
|
+
expect {
|
40
|
+
matcher.matches?(method)
|
41
|
+
}.to change {
|
42
|
+
matcher.failure_message
|
43
|
+
}.to(
|
44
|
+
'expected "b" to a keyword parameter in example_method ' \
|
45
|
+
'parameter list [[:key, :a]]'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#failure_message_when_negated' do
|
51
|
+
it 'says the keyword is a method parameter, but was not expected' do
|
52
|
+
method = instance_double(Method)
|
53
|
+
allow(method).to receive(:name).and_return(:example_method)
|
54
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
55
|
+
matcher = KeywordParameterMatchers::HaveKeywordParameter.new(
|
56
|
+
:a
|
57
|
+
)
|
58
|
+
|
59
|
+
expect {
|
60
|
+
matcher.matches?(method)
|
61
|
+
}.to change {
|
62
|
+
matcher.failure_message_when_negated
|
63
|
+
}.to(
|
64
|
+
'expected "a" not to a keyword parameter in example_method ' \
|
65
|
+
'parameter list [[:key, :a]]'
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KeywordParameterMatchers::HaveOptionalKeywordParameter do
|
4
|
+
describe '#matches?' do
|
5
|
+
it 'returns true when the keyword is a optional method parameter' do
|
6
|
+
method = instance_double(Method)
|
7
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
8
|
+
matcher = KeywordParameterMatchers::HaveOptionalKeywordParameter.new(
|
9
|
+
:a
|
10
|
+
)
|
11
|
+
|
12
|
+
expect(
|
13
|
+
matcher.matches?(method)
|
14
|
+
).to eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false when the keyword is not a optional method parameter' do
|
18
|
+
method = instance_double(Method)
|
19
|
+
allow(method).to receive(:parameters).and_return([[:keyreq, :a]])
|
20
|
+
matcher = KeywordParameterMatchers::HaveOptionalKeywordParameter.new(
|
21
|
+
:a
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(
|
25
|
+
matcher.matches?(method)
|
26
|
+
).to eq(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#failure_message' do
|
31
|
+
it 'says the keyword is not a optional method parameter' do
|
32
|
+
method = instance_double(Method)
|
33
|
+
allow(method).to receive(:name).and_return(:example_method)
|
34
|
+
allow(method).to receive(:parameters).and_return([[:keyreq, :a]])
|
35
|
+
matcher = KeywordParameterMatchers::HaveOptionalKeywordParameter.new(
|
36
|
+
:a
|
37
|
+
)
|
38
|
+
|
39
|
+
expect {
|
40
|
+
matcher.matches?(method)
|
41
|
+
}.to change {
|
42
|
+
matcher.failure_message
|
43
|
+
}.to(
|
44
|
+
'expected "a" to be a optional keyword parameter in ' \
|
45
|
+
'example_method parameter list [[:keyreq, :a]]'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#failure_message_when_negated' do
|
51
|
+
it 'says the keyword is a method parameter, but was not expected' do
|
52
|
+
method = instance_double(Method)
|
53
|
+
allow(method).to receive(:name).and_return(:example_method)
|
54
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
55
|
+
matcher = KeywordParameterMatchers::HaveOptionalKeywordParameter.new(
|
56
|
+
:a
|
57
|
+
)
|
58
|
+
|
59
|
+
expect {
|
60
|
+
matcher.matches?(method)
|
61
|
+
}.to change {
|
62
|
+
matcher.failure_message_when_negated
|
63
|
+
}.to(
|
64
|
+
'expected "a" not to be an optional keyword parameter in ' \
|
65
|
+
'example_method parameter list [[:key, :a]]'
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KeywordParameterMatchers::HaveRequiredKeywordParameter do
|
4
|
+
describe '#matches?' do
|
5
|
+
it 'returns true when the keyword is a required method parameter' do
|
6
|
+
method = instance_double(Method)
|
7
|
+
allow(method).to receive(:parameters).and_return([[:keyreq, :a]])
|
8
|
+
matcher = KeywordParameterMatchers::HaveRequiredKeywordParameter.new(
|
9
|
+
:a
|
10
|
+
)
|
11
|
+
|
12
|
+
expect(
|
13
|
+
matcher.matches?(method)
|
14
|
+
).to eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false when the keyword is not a required method parameter' do
|
18
|
+
method = instance_double(Method)
|
19
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
20
|
+
matcher = KeywordParameterMatchers::HaveRequiredKeywordParameter.new(
|
21
|
+
:a
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(
|
25
|
+
matcher.matches?(method)
|
26
|
+
).to eq(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#failure_message' do
|
31
|
+
it 'says the keyword is not a required method parameter' do
|
32
|
+
method = instance_double(Method)
|
33
|
+
allow(method).to receive(:name).and_return(:example_method)
|
34
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
35
|
+
matcher = KeywordParameterMatchers::HaveRequiredKeywordParameter.new(
|
36
|
+
:a
|
37
|
+
)
|
38
|
+
|
39
|
+
expect {
|
40
|
+
matcher.matches?(method)
|
41
|
+
}.to change {
|
42
|
+
matcher.failure_message
|
43
|
+
}.to(
|
44
|
+
'expected "a" to be a required keyword parameter in ' \
|
45
|
+
'example_method parameter list [[:key, :a]]'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#failure_message_when_negated' do
|
51
|
+
it 'says the keyword is a method parameter, but was not expected' do
|
52
|
+
method = instance_double(Method)
|
53
|
+
allow(method).to receive(:name).and_return(:example_method)
|
54
|
+
allow(method).to receive(:parameters).and_return([[:key, :a]])
|
55
|
+
matcher = KeywordParameterMatchers::HaveRequiredKeywordParameter.new(
|
56
|
+
:a
|
57
|
+
)
|
58
|
+
|
59
|
+
expect {
|
60
|
+
matcher.matches?(method)
|
61
|
+
}.to change {
|
62
|
+
matcher.failure_message_when_negated
|
63
|
+
}.to(
|
64
|
+
'expected "a" not to be an required keyword parameter in ' \
|
65
|
+
'example_method parameter list [[:key, :a]]'
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KeywordParameterMatchers::MatcherHelpers do
|
4
|
+
describe '#have_keyword_parameter' do
|
5
|
+
it 'returns a HaveKeywordParameter matcher' do
|
6
|
+
dummy_object = instance_double('DummyObject')
|
7
|
+
dummy_object.extend(KeywordParameterMatchers::MatcherHelpers)
|
8
|
+
|
9
|
+
expect(
|
10
|
+
dummy_object.have_keyword_parameter(:a)
|
11
|
+
).to be_kind_of(
|
12
|
+
KeywordParameterMatchers::HaveKeywordParameter
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets the expected value' do
|
17
|
+
dummy_object = instance_double('DummyObject')
|
18
|
+
dummy_object.extend(KeywordParameterMatchers::MatcherHelpers)
|
19
|
+
|
20
|
+
expect(
|
21
|
+
dummy_object
|
22
|
+
.have_keyword_parameter(:a)
|
23
|
+
.send(:expected)
|
24
|
+
).to eq(:a)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#have_optional_keyword_parameter' do
|
29
|
+
it 'returns a HaveOptionalKeywordParameter matcher' do
|
30
|
+
dummy_object = instance_double('DummyObject')
|
31
|
+
dummy_object.extend(KeywordParameterMatchers::MatcherHelpers)
|
32
|
+
|
33
|
+
expect(
|
34
|
+
dummy_object.have_optional_keyword_parameter(:a)
|
35
|
+
).to be_kind_of(
|
36
|
+
KeywordParameterMatchers::HaveOptionalKeywordParameter
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sets the expected value' do
|
41
|
+
dummy_object = instance_double('DummyObject')
|
42
|
+
dummy_object.extend(KeywordParameterMatchers::MatcherHelpers)
|
43
|
+
|
44
|
+
expect(
|
45
|
+
dummy_object
|
46
|
+
.have_optional_keyword_parameter(:a)
|
47
|
+
.send(:expected)
|
48
|
+
).to eq(:a)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#have_required_keyword_parameter' do
|
53
|
+
it 'returns a HaveRequiredKeywordParameter matcher' do
|
54
|
+
dummy_object = instance_double('DummyObject')
|
55
|
+
dummy_object.extend(KeywordParameterMatchers::MatcherHelpers)
|
56
|
+
|
57
|
+
expect(
|
58
|
+
dummy_object.have_required_keyword_parameter(:a)
|
59
|
+
).to be_kind_of(
|
60
|
+
KeywordParameterMatchers::HaveRequiredKeywordParameter
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'sets the expected value' do
|
65
|
+
dummy_object = instance_double('DummyObject')
|
66
|
+
dummy_object.extend(KeywordParameterMatchers::MatcherHelpers)
|
67
|
+
|
68
|
+
expect(
|
69
|
+
dummy_object
|
70
|
+
.have_required_keyword_parameter(:a)
|
71
|
+
.send(:expected)
|
72
|
+
).to eq(:a)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KeywordParameterMatchers::NullMethod do
|
4
|
+
describe '.new_if_nil' do
|
5
|
+
it 'returns a new instance if the method is nil' do
|
6
|
+
method = nil
|
7
|
+
|
8
|
+
expect(
|
9
|
+
KeywordParameterMatchers::NullMethod.new_if_nil(method)
|
10
|
+
).to be_kind_of(KeywordParameterMatchers::NullMethod)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a the method if the method is not nil' do
|
14
|
+
method = instance_double(Method)
|
15
|
+
|
16
|
+
expect(
|
17
|
+
KeywordParameterMatchers::NullMethod.new_if_nil(method)
|
18
|
+
).to eq(method)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#name' do
|
23
|
+
it 'returns a empty string' do
|
24
|
+
null_method = KeywordParameterMatchers::NullMethod.new_if_nil(nil)
|
25
|
+
|
26
|
+
expect(
|
27
|
+
null_method.name
|
28
|
+
).to eq('')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#parameters' do
|
33
|
+
it 'returns a empty array' do
|
34
|
+
null_method = KeywordParameterMatchers::NullMethod.new_if_nil(nil)
|
35
|
+
|
36
|
+
expect(
|
37
|
+
null_method.parameters
|
38
|
+
).to eq([])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'keyword_parameter_matchers'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |expectations|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
|
+
end
|
7
|
+
|
8
|
+
config.mock_with :rspec do |mocks|
|
9
|
+
mocks.verify_partial_doubles = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.order = :random
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keyword_parameter_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Terry Finn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- terry@terryrfinn.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- keyword_parameter_matchers.gemspec
|
82
|
+
- lib/keyword_parameter_matchers.rb
|
83
|
+
- lib/keyword_parameter_matchers/have_keyword_parameter.rb
|
84
|
+
- lib/keyword_parameter_matchers/have_optional_keyword_parameter.rb
|
85
|
+
- lib/keyword_parameter_matchers/have_required_keyword_parameter.rb
|
86
|
+
- lib/keyword_parameter_matchers/matcher_helpers.rb
|
87
|
+
- lib/keyword_parameter_matchers/null_method.rb
|
88
|
+
- lib/keyword_parameter_matchers/rspec.rb
|
89
|
+
- lib/keyword_parameter_matchers/version.rb
|
90
|
+
- spec/keyword_parameter_matchers/have_keyword_parameter_spec.rb
|
91
|
+
- spec/keyword_parameter_matchers/have_optional_keyword_parameter_spec.rb
|
92
|
+
- spec/keyword_parameter_matchers/have_required_keyword_parameter_spec.rb
|
93
|
+
- spec/keyword_parameter_matchers/matcher_helpers_spec.rb
|
94
|
+
- spec/keyword_parameter_matchers/null_method_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: https://github.com/terryfinn/keyword_parameter_matchers
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.5
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Simple matchers for method keyword parameters.
|
120
|
+
test_files:
|
121
|
+
- spec/keyword_parameter_matchers/have_keyword_parameter_spec.rb
|
122
|
+
- spec/keyword_parameter_matchers/have_optional_keyword_parameter_spec.rb
|
123
|
+
- spec/keyword_parameter_matchers/have_required_keyword_parameter_spec.rb
|
124
|
+
- spec/keyword_parameter_matchers/matcher_helpers_spec.rb
|
125
|
+
- spec/keyword_parameter_matchers/null_method_spec.rb
|
126
|
+
- spec/spec_helper.rb
|