rspec-crispy 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +4 -0
- data/.travis.yml +24 -0
- data/ChangeLog.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +7 -0
- data/lib/rspec/crispy.rb +19 -0
- data/lib/rspec/crispy/crispy_features.rb +141 -0
- data/lib/rspec/crispy/crispy_hooks.rb +21 -0
- data/lib/rspec/crispy/version.rb +5 -0
- data/rspec-crispy.gemspec +26 -0
- data/spec/rspec/crispy/configure_without_conflict_spec.rb +311 -0
- data/spec/rspec/crispy/mock_with_rspec_crispy_spec.rb +55 -0
- data/spec/spec_helper.rb +4 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 975eea13379eab4798635ad3c963adeb20c32024
|
4
|
+
data.tar.gz: f9c12b537253972d23867957905999da5e827400
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f4acd1fe3ff5891354509b6a1ff37d7a1b732699ed51abe98f866215741b53eb069ef02bf6bf59d22ab0f1cec03163ffa11144fedccff35822341326a7b9cb5
|
7
|
+
data.tar.gz: fdd735dfc43960a0536788d9a5f3f5203e55160b70ac2e3c763d22d972599c7f2b7c9e44a7a90493db234e646eed69262cf1dce832c035c113bf934cd2fa919f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
install:
|
3
|
+
- gem install bundler
|
4
|
+
- CODECLIMATE_REPO_TOKEN=0f952da7b3b1345e9c0ad6e4b2a4dfa4479f3788efd933fb0598edecf429ed51 bundle
|
5
|
+
rvm:
|
6
|
+
- ruby-head
|
7
|
+
- 2.2.0
|
8
|
+
- 2.1.5
|
9
|
+
- 2.0.0
|
10
|
+
script:
|
11
|
+
- CODECLIMATE_REPO_TOKEN=0f952da7b3b1345e9c0ad6e4b2a4dfa4479f3788efd933fb0598edecf429ed51 bundle exec rspec spec/rspec/crispy/configure_without_conflict_spec.rb
|
12
|
+
- bundle exec rspec spec/rspec/crispy/mock_with_rspec_crispy_spec.rb
|
13
|
+
notifications:
|
14
|
+
email:
|
15
|
+
recipients:
|
16
|
+
- whosekiteneverfly@gmail.com
|
17
|
+
on_success: never
|
18
|
+
on_failure: never
|
19
|
+
addons:
|
20
|
+
code_climate:
|
21
|
+
repo_token: 0f952da7b3b1345e9c0ad6e4b2a4dfa4479f3788efd933fb0598edecf429ed51
|
22
|
+
matrix:
|
23
|
+
allow_failures:
|
24
|
+
- rvm: ruby-head
|
data/ChangeLog.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yuji Yamamoto
|
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,84 @@
|
|
1
|
+
# RSpec::Crispy
|
2
|
+
|
3
|
+
[](https://travis-ci.org/igrep/rspec-crispy)
|
4
|
+
[](https://codeclimate.com/github/igrep/rspec-crispy)
|
5
|
+
[](https://codeclimate.com/github/igrep/rspec-crispy)
|
6
|
+
|
7
|
+
Custom matchers for RSpec to call [Crispy](https://github.com/igrep/crispy)'s API.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'rspec-crispy'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install rspec-crispy
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Use with rspec-mocks
|
28
|
+
|
29
|
+
Add `::RSpec::Crispy.configure_without_conflict config` in your `spec_helper.rb`.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
RSpec.configure do|config|
|
33
|
+
config.mock_with(:rspec)
|
34
|
+
::RSpec::Crispy.configure_without_conflict config
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Then, `include ::RSpec::Crispy::CrispyFeatures` in a context where you want to use the features.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
RSpec.describe YourClass do
|
42
|
+
|
43
|
+
subject { YourClass }
|
44
|
+
|
45
|
+
context 'use crispy' do
|
46
|
+
include ::RSpec::Crispy::CrispyFeatures
|
47
|
+
|
48
|
+
before do
|
49
|
+
spy_into subject
|
50
|
+
subject.new.hoge
|
51
|
+
end
|
52
|
+
|
53
|
+
it { is_expected.to have_received(:foo) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'use rspec-mocks' do
|
57
|
+
it 'calls foo' do
|
58
|
+
expect(subject).to have_receive(:foo)
|
59
|
+
subject.new.hoge
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### Use only rspec-crispy (without rspec-mocks)
|
67
|
+
|
68
|
+
TODO: Write usage instructions here
|
69
|
+
|
70
|
+
### Available Crispy API
|
71
|
+
|
72
|
+
TODO: Write usage instructions here
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( https://github.com/igrep/rspec-crispy/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create a new Pull Request
|
81
|
+
|
82
|
+
### NOTE
|
83
|
+
|
84
|
+
- You must use **`rake test`** to run `rspec spec/rspec/crispy/configure_without_conflict_spec.rb` and `rspec spec/rspec/crispy/mock_with_rspec_crispy_spec.rb` separately. **DO NOT** run all specs at once by `rspec spec`.
|
data/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
task :test do
|
4
|
+
# split spec execution by whether overwrite rspec-mock's API or not. see `git show f460ae689692a8b1c667f1a8f40e815f51aa91df`.
|
5
|
+
sh 'bundle exec rspec spec/rspec/crispy/mock_with_rspec_crispy_spec.rb'
|
6
|
+
sh 'bundle exec rspec spec/rspec/crispy/configure_without_conflict_spec.rb'
|
7
|
+
end
|
data/lib/rspec/crispy.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rspec/crispy/crispy_hooks'
|
2
|
+
require 'rspec/crispy/crispy_features'
|
3
|
+
require 'rspec/crispy/version'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Crispy
|
7
|
+
include ::RSpec::Crispy::CrispyHooks
|
8
|
+
include ::RSpec::Crispy::CrispyFeatures
|
9
|
+
|
10
|
+
def self.framework_name
|
11
|
+
:crispy
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure_without_conflict config
|
15
|
+
config.after(:each){ ::Crispy::CrispyWorld.reset }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'crispy'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Crispy
|
5
|
+
module CrispyFeatures
|
6
|
+
|
7
|
+
include ::Crispy
|
8
|
+
|
9
|
+
def expect_any_instance_of klass
|
10
|
+
CrispyExpectAnyInstanceOf.new klass
|
11
|
+
end
|
12
|
+
|
13
|
+
def have_received method_name, *arguments
|
14
|
+
CrispyHaveReceived.new method_name, *arguments
|
15
|
+
end
|
16
|
+
|
17
|
+
class CrispyExpectAnyInstanceOf
|
18
|
+
|
19
|
+
def initialize klass
|
20
|
+
@klass = klass
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_spy_of_instances
|
24
|
+
::Crispy.spy_of_instances(@klass)
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"<Some Instances of #@klass>"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class CrispyHaveReceived
|
34
|
+
|
35
|
+
def initialize method_name, *arguments
|
36
|
+
@method_name = method_name
|
37
|
+
@arguments = arguments
|
38
|
+
end
|
39
|
+
|
40
|
+
def name
|
41
|
+
'have_received'.freeze
|
42
|
+
end
|
43
|
+
|
44
|
+
def matches?(subject)
|
45
|
+
@subject = subject
|
46
|
+
@spy_of_subject = spy_of_subject subject
|
47
|
+
matched_spy?(@spy_of_subject)
|
48
|
+
end
|
49
|
+
|
50
|
+
def matched_spy? spy
|
51
|
+
spy.received? @method_name, *@arguments
|
52
|
+
end
|
53
|
+
|
54
|
+
def once
|
55
|
+
times 1
|
56
|
+
end
|
57
|
+
|
58
|
+
def times n
|
59
|
+
NTimes.new n, @method_name, *@arguments
|
60
|
+
end
|
61
|
+
|
62
|
+
def failure_message
|
63
|
+
@spy_of_subject.stop
|
64
|
+
result = "Expected #{@subject.inspect} to have received :#@method_name method"
|
65
|
+
result << " with #@arguments" unless @arguments.empty?
|
66
|
+
result << ".\n"
|
67
|
+
result << actually_received_messages_for_failure_message
|
68
|
+
result
|
69
|
+
end
|
70
|
+
|
71
|
+
def failure_message_when_negated
|
72
|
+
@spy_of_subject.stop
|
73
|
+
result = "Expected #{@subject.inspect} NOT to have received :#@method_name method"
|
74
|
+
result << " with #@arguments" unless @arguments.empty?
|
75
|
+
result << ". But actually received.\n".freeze
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
def actually_received_messages_for_failure_message
|
80
|
+
if @spy_of_subject.received_messages.empty?
|
81
|
+
"Actually, it has received no messages.\n".freeze
|
82
|
+
else
|
83
|
+
result = "Actually, it has received these messages:\n"
|
84
|
+
@spy_of_subject.received_messages.each do|received_message|
|
85
|
+
arguments_for_message = received_message.arguments.map(&:inspect).join(', '.freeze)
|
86
|
+
# TODO: which instance actually received the message for ClassSpy
|
87
|
+
result << " it.#{received_message.method_name}(#{arguments_for_message})\n"
|
88
|
+
end
|
89
|
+
result
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def spy_of_subject subject
|
94
|
+
# Don't use instance_of? method. it records received_messages.
|
95
|
+
if CrispyExpectAnyInstanceOf === subject
|
96
|
+
subject.get_spy_of_instances
|
97
|
+
else
|
98
|
+
::Crispy.spy(subject)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class NTimes < self
|
103
|
+
|
104
|
+
def initialize n, method_name, *arguments
|
105
|
+
super(method_name, *arguments)
|
106
|
+
@n = n
|
107
|
+
end
|
108
|
+
|
109
|
+
def matched_spy? spy
|
110
|
+
@actual_count = spy.count_received(@method_name, *@arguments)
|
111
|
+
@n == @actual_count
|
112
|
+
end
|
113
|
+
|
114
|
+
def failure_message
|
115
|
+
@spy_of_subject.stop
|
116
|
+
result = "Expected #{@subject.inspect} to have received :#@method_name method"
|
117
|
+
result << " with #@arguments" unless @arguments.empty?
|
118
|
+
result << " some particular times.\n"
|
119
|
+
result << " Expected: #@n times.\n"
|
120
|
+
result << " Actual: #@actual_count times.\n"
|
121
|
+
result << actually_received_messages_for_failure_message
|
122
|
+
result
|
123
|
+
end
|
124
|
+
|
125
|
+
def failure_message_when_negated
|
126
|
+
@spy_of_subject.stop
|
127
|
+
result = "Expected #{@subject.inspect} to have received :#@method_name method"
|
128
|
+
result << " with #@arguments" unless @arguments.empty?
|
129
|
+
result << " NOT #@n times.\n"
|
130
|
+
result << actually_received_messages_for_failure_message
|
131
|
+
result
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'crispy'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Crispy
|
5
|
+
module CrispyHooks
|
6
|
+
|
7
|
+
# required methods by RSpec's mock framework adapter API.
|
8
|
+
|
9
|
+
def setup_mocks_for_rspec
|
10
|
+
end
|
11
|
+
|
12
|
+
def verify_mocks_for_rspec
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown_mocks_for_rspec
|
16
|
+
::Crispy::CrispyWorld.reset
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/crispy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-crispy"
|
8
|
+
spec.version = RSpec::Crispy::VERSION
|
9
|
+
spec.authors = ["Yamamoto Yuji"]
|
10
|
+
spec.email = ["whosekiteneverfly@gmail.com"]
|
11
|
+
spec.summary = %q{RSpec plugin for Crispy you can use with rspec-mocks.}
|
12
|
+
spec.description = %q{RSpec plugin for Crispy you can use with rspec-mocks. Privides matchers such as have_received to use Crispy's API in RSpec's way.}
|
13
|
+
spec.homepage = "https://github.com/igrep/rspec-crispy"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = []
|
18
|
+
spec.test_files = spec.files.grep(%r{\Aspec/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_runtime_dependency "crispy", ">= 0.3.3"
|
26
|
+
end
|
@@ -0,0 +1,311 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec/crispy'
|
3
|
+
|
4
|
+
RSpec.configure do|config|
|
5
|
+
config.mock_with(:rspec)
|
6
|
+
::RSpec::Crispy.configure_without_conflict config
|
7
|
+
end
|
8
|
+
|
9
|
+
class ObjectClass
|
10
|
+
|
11
|
+
CONSTANT_TO_STUB = ::Crispy.double('value_before_stubbed')
|
12
|
+
|
13
|
+
def instance_hoge _, _, _
|
14
|
+
end
|
15
|
+
def instance_foo
|
16
|
+
end
|
17
|
+
def instance_never_called *_arguments
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.hoge a, b, c
|
21
|
+
private_foo a
|
22
|
+
[a, b, c]
|
23
|
+
end
|
24
|
+
def self.foo
|
25
|
+
123
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.never_called *_arguments
|
29
|
+
fail 'You should not call this method!'
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.stubbed_method1
|
33
|
+
'before stubbed 1'
|
34
|
+
end
|
35
|
+
def self.stubbed_method2
|
36
|
+
'before stubbed 2'
|
37
|
+
end
|
38
|
+
def self.stubbed_method3
|
39
|
+
'before stubbed 3'
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.private_foo _
|
43
|
+
:private_foo
|
44
|
+
end
|
45
|
+
private_class_method :private_foo
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
RSpec.describe ::RSpec::Crispy do
|
50
|
+
|
51
|
+
context 'when including' do
|
52
|
+
include ::RSpec::Crispy::CrispyFeatures
|
53
|
+
|
54
|
+
describe '#spy_into' do
|
55
|
+
it 'makes a Crispy\'s spy.' do
|
56
|
+
expect(spy_into(Object.new)).to be_instance_of ::Crispy::CrispyInternal::Spy
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#spy_into_instances' do
|
61
|
+
it 'makes a Crispy\'s class spy.' do
|
62
|
+
expect(spy_into_instances(Class.new)).to be_instance_of ::Crispy::CrispyInternal::ClassSpy
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#spy' do
|
67
|
+
it 'returns a Crispy\'s spy.' do
|
68
|
+
object = Object.new
|
69
|
+
spy_into(object)
|
70
|
+
expect(spy(object)).to be_instance_of ::Crispy::CrispyInternal::Spy
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#spy_of_instances' do
|
75
|
+
it 'returns a Crispy\'s class spy.' do
|
76
|
+
klass = Class.new
|
77
|
+
spy_into_instances klass
|
78
|
+
expect(spy_of_instances(klass)).to be_instance_of ::Crispy::CrispyInternal::ClassSpy
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#double' do
|
83
|
+
it 'returns a Crispy\'s double.' do
|
84
|
+
expect(double('name')).to be_instance_of ::Crispy::CrispyInternal::Double
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
shared_examples_for 'matches and then produces failure_message_when_negated' do
|
89
|
+
it 'matches' do
|
90
|
+
expect(result).to be true
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'it produces failure_message_when_negated' do
|
94
|
+
# The failure message should be checked by your own eyes. Is it easy to read?
|
95
|
+
puts subject.failure_message_when_negated
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
shared_examples_for 'doesn\'match and then produces failure_message' do
|
100
|
+
it 'doesn\'t match' do
|
101
|
+
expect(result).to be false
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'it produces failure_message' do
|
105
|
+
# The failure message should be checked by your own eyes. Is it easy to read?
|
106
|
+
puts subject.failure_message
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#have_received' do
|
111
|
+
let!(:non_used_object){ ObjectClass.new }
|
112
|
+
before do
|
113
|
+
spy_into(ObjectClass)
|
114
|
+
ObjectClass.hoge 1, 1, 1
|
115
|
+
ObjectClass.hoge 2, 2, 2
|
116
|
+
|
117
|
+
spy_into(non_used_object)
|
118
|
+
end
|
119
|
+
|
120
|
+
subject { have_received(method_name, *arguments) }
|
121
|
+
let!(:result){ subject.matches? ObjectClass }
|
122
|
+
|
123
|
+
context 'without arguments' do
|
124
|
+
let(:arguments){ [] }
|
125
|
+
|
126
|
+
context 'given a method ObjectClass actually called' do
|
127
|
+
let(:method_name){ :hoge }
|
128
|
+
|
129
|
+
it_should_behave_like 'matches and then produces failure_message_when_negated'
|
130
|
+
|
131
|
+
context 'given an object spy_into-ed but not used as matches?\'s argument' do
|
132
|
+
let!(:result){ subject.matches? non_used_object }
|
133
|
+
|
134
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
135
|
+
|
136
|
+
it 'its failure_message tells the subject has received no messages' do
|
137
|
+
expect(subject.failure_message).to include("Actually, it has received no messages.\n")
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'given a method ObjectClass didn\'t call' do
|
145
|
+
let(:method_name){ :never_called }
|
146
|
+
|
147
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
148
|
+
|
149
|
+
it 'its failure_message tells ObjectClass\'s received messages' do
|
150
|
+
expect(subject.failure_message).to(
|
151
|
+
include('hoge(1, 1, 1)') & include('hoge(2, 2, 2)')
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'with arguments' do
|
160
|
+
|
161
|
+
context 'given a method and arguments ObjectClass actually called' do
|
162
|
+
let(:method_name){ :hoge }
|
163
|
+
let(:arguments){ [1, 1, 1] }
|
164
|
+
|
165
|
+
it_should_behave_like 'matches and then produces failure_message_when_negated'
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'given a method ObjectClass actually called, and not received arguments' do
|
169
|
+
let(:method_name){ :hoge }
|
170
|
+
let(:arguments){ [3, 3, 3] }
|
171
|
+
|
172
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '.have_received.once' do
|
180
|
+
let!(:non_used_object){ ObjectClass.new }
|
181
|
+
before do
|
182
|
+
spy_into(ObjectClass)
|
183
|
+
ObjectClass.foo
|
184
|
+
ObjectClass.hoge 1, 1, 1
|
185
|
+
ObjectClass.hoge 2, 2, 2
|
186
|
+
ObjectClass.hoge 2, 2, 2
|
187
|
+
|
188
|
+
spy_into(non_used_object)
|
189
|
+
end
|
190
|
+
|
191
|
+
subject { have_received(method_name, *arguments).once }
|
192
|
+
let!(:result){ subject.matches? ObjectClass }
|
193
|
+
|
194
|
+
context 'without arguments' do
|
195
|
+
let(:arguments){ [] }
|
196
|
+
|
197
|
+
context 'given a method ObjectClass actually called once' do
|
198
|
+
let(:method_name){ :foo }
|
199
|
+
|
200
|
+
it_should_behave_like 'matches and then produces failure_message_when_negated'
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'given a method ObjectClass actually called more than once' do
|
204
|
+
let(:method_name){ :hoge }
|
205
|
+
|
206
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'given a method ObjectClass didn\'t call' do
|
210
|
+
let(:method_name){ :never_called }
|
211
|
+
|
212
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'with arguments' do
|
218
|
+
|
219
|
+
context 'given a method and arguments ObjectClass\'s instances actually called once' do
|
220
|
+
let(:method_name){ :hoge }
|
221
|
+
let(:arguments){ [1, 1, 1] }
|
222
|
+
|
223
|
+
it_should_behave_like 'matches and then produces failure_message_when_negated'
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'given a method ObjectClass\'s instances actually called once, but given arguments received twice' do
|
227
|
+
let(:method_name){ :hoge }
|
228
|
+
let(:arguments){ [2, 2, 2] }
|
229
|
+
|
230
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe '#expect_any_instance_of' do
|
237
|
+
before do
|
238
|
+
spy_into_instances ObjectClass
|
239
|
+
|
240
|
+
ObjectClass.new.instance_hoge 9, 9, 9
|
241
|
+
ObjectClass.new.instance_hoge 8, 8, 8
|
242
|
+
ObjectClass.new.instance_foo
|
243
|
+
|
244
|
+
ObjectClass.hoge 9, 9, 9
|
245
|
+
ObjectClass.hoge 8, 8, 8
|
246
|
+
ObjectClass.foo
|
247
|
+
end
|
248
|
+
|
249
|
+
let(:subject_of_matcher){ expect_any_instance_of ObjectClass }
|
250
|
+
|
251
|
+
describe '.have_received' do
|
252
|
+
subject { have_received(method_name, *arguments) }
|
253
|
+
let!(:result){ subject.matches? subject_of_matcher }
|
254
|
+
|
255
|
+
context 'without arguments' do
|
256
|
+
let(:arguments){ [] }
|
257
|
+
|
258
|
+
context 'given a method ObjectClass\'s instances actually called' do
|
259
|
+
let(:method_name){ :instance_hoge }
|
260
|
+
|
261
|
+
it_should_behave_like 'matches and then produces failure_message_when_negated'
|
262
|
+
end
|
263
|
+
|
264
|
+
context 'given a method none of the ObjectClass\'s instances called' do
|
265
|
+
let(:method_name){ :instance_never_called }
|
266
|
+
let!(:result){ subject.matches? subject_of_matcher }
|
267
|
+
|
268
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
context 'with arguments' do
|
274
|
+
|
275
|
+
context 'given a method and arguments ObjectClass\'s instances actually called' do
|
276
|
+
let(:method_name){ :instance_hoge }
|
277
|
+
let(:arguments){ [9, 9, 9] }
|
278
|
+
|
279
|
+
it { is_expected.to be_matches(subject_of_matcher) }
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'given a method ObjectClass\'s instances actually called, but given not received arguments' do
|
283
|
+
let(:method_name){ :instance_hoge }
|
284
|
+
let(:arguments){ [7, 7, 7] }
|
285
|
+
let!(:result){ subject.matches? subject_of_matcher }
|
286
|
+
|
287
|
+
it_should_behave_like 'doesn\'match and then produces failure_message'
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'when not including' do
|
299
|
+
|
300
|
+
describe '#spy' do
|
301
|
+
end
|
302
|
+
|
303
|
+
describe '#double' do
|
304
|
+
end
|
305
|
+
|
306
|
+
describe '#have_received' do
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec/crispy'
|
3
|
+
|
4
|
+
RSpec.configure do|config|
|
5
|
+
config.mock_with ::RSpec::Crispy
|
6
|
+
end
|
7
|
+
|
8
|
+
class SomeClass
|
9
|
+
|
10
|
+
SOME_CONSTANT = 'not stubbed'
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec.describe ::RSpec::Crispy do
|
15
|
+
|
16
|
+
describe '#spy' do
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#double' do
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#have_received' do
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#have_received_once' do
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#stub_const' do
|
29
|
+
|
30
|
+
context 'when stubs' do
|
31
|
+
before do
|
32
|
+
spy_into(::Crispy::CrispyInternal::ConstChanger)
|
33
|
+
|
34
|
+
stub_const 'SomeClass::SOME_CONSTANT', 'stubbed'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'mutates the value of constant' do
|
38
|
+
expect(SomeClass::SOME_CONSTANT).to eq 'stubbed'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'calls ::Crispy::CrispyInternal::ConstChanger.change_by_full_name' do
|
42
|
+
expect(spy(::Crispy::CrispyInternal::ConstChanger).received?(:change_by_full_name, 'SomeClass::SOME_CONSTANT', 'stubbed')).to be true
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when not stubs' do
|
48
|
+
it 'doesn\'t mutate the value of constant' do
|
49
|
+
expect(SomeClass::SOME_CONSTANT).to eq 'not stubbed'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-crispy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yamamoto Yuji
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-03 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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: crispy
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.3.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.3.3
|
69
|
+
description: RSpec plugin for Crispy you can use with rspec-mocks. Privides matchers
|
70
|
+
such as have_received to use Crispy's API in RSpec's way.
|
71
|
+
email:
|
72
|
+
- whosekiteneverfly@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- ChangeLog.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- lib/rspec/crispy.rb
|
86
|
+
- lib/rspec/crispy/crispy_features.rb
|
87
|
+
- lib/rspec/crispy/crispy_hooks.rb
|
88
|
+
- lib/rspec/crispy/version.rb
|
89
|
+
- rspec-crispy.gemspec
|
90
|
+
- spec/rspec/crispy/configure_without_conflict_spec.rb
|
91
|
+
- spec/rspec/crispy/mock_with_rspec_crispy_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: https://github.com/igrep/rspec-crispy
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.5
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: RSpec plugin for Crispy you can use with rspec-mocks.
|
117
|
+
test_files:
|
118
|
+
- spec/rspec/crispy/configure_without_conflict_spec.rb
|
119
|
+
- spec/rspec/crispy/mock_with_rspec_crispy_spec.rb
|
120
|
+
- spec/spec_helper.rb
|