rspec-varys 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 +22 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/features/generating_specs.feature +209 -0
- data/features/readme.md +10 -0
- data/features/support/env.rb +1 -0
- data/lib/rspec/varys/version.rb +5 -0
- data/lib/rspec/varys.rb +155 -0
- data/rspec-varys.gemspec +26 -0
- data/spec/rspec/varys_spec.rb +113 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1ee4c82227c770124d98e6ea57320b37e2dbceb
|
4
|
+
data.tar.gz: bc60a41dc4f3ea42206f83a601170c20cc98cfae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2609cf4e8e4b3f70bb97beb03a602bbee9ea7c7785f5bb65c6b4585cf9759da9cb1183b4210ee0ef2a317761d7b69b7f30c280a3c62dd6d29464fb02396d2fd0
|
7
|
+
data.tar.gz: 8ffd607d581171121703f2090f6870e2efb5a323f02260e2ceb86203edf052defe274d38e9150eb644ca1a2e48596e80e864943913c547cd39cb4bcfb8e80b43
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
aruba (0.6.2)
|
5
|
+
childprocess (>= 0.3.6)
|
6
|
+
cucumber (>= 1.1.1)
|
7
|
+
rspec-expectations (>= 2.7.0)
|
8
|
+
binding_of_caller (0.7.2)
|
9
|
+
debug_inspector (>= 0.0.1)
|
10
|
+
bond (0.5.1)
|
11
|
+
builder (3.2.2)
|
12
|
+
childprocess (0.5.5)
|
13
|
+
ffi (~> 1.0, >= 1.0.11)
|
14
|
+
clipboard (1.0.5)
|
15
|
+
coderay (1.1.0)
|
16
|
+
cucumber (1.3.15)
|
17
|
+
builder (>= 2.1.2)
|
18
|
+
diff-lcs (>= 1.1.3)
|
19
|
+
gherkin (~> 2.12)
|
20
|
+
multi_json (>= 1.7.5, < 2.0)
|
21
|
+
multi_test (>= 0.1.1)
|
22
|
+
debug_inspector (0.0.2)
|
23
|
+
diff-lcs (1.2.5)
|
24
|
+
ffi (1.9.6)
|
25
|
+
gherkin (2.12.2)
|
26
|
+
multi_json (~> 1.3)
|
27
|
+
interception (0.5)
|
28
|
+
method_source (0.8.2)
|
29
|
+
multi_json (1.10.1)
|
30
|
+
multi_test (0.1.1)
|
31
|
+
pry (0.10.1)
|
32
|
+
coderay (~> 1.1.0)
|
33
|
+
method_source (~> 0.8.1)
|
34
|
+
slop (~> 3.4)
|
35
|
+
pry-clipboard (0.1.1)
|
36
|
+
clipboard
|
37
|
+
pry
|
38
|
+
pry-rescue (1.4.1)
|
39
|
+
interception (>= 0.5)
|
40
|
+
pry
|
41
|
+
pry-stack_explorer (0.4.9.1)
|
42
|
+
binding_of_caller (>= 0.7)
|
43
|
+
pry (>= 0.9.11)
|
44
|
+
rspec (3.1.0)
|
45
|
+
rspec-core (~> 3.1.0)
|
46
|
+
rspec-expectations (~> 3.1.0)
|
47
|
+
rspec-mocks (~> 3.1.0)
|
48
|
+
rspec-core (3.1.7)
|
49
|
+
rspec-support (~> 3.1.0)
|
50
|
+
rspec-expectations (3.1.2)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.1.0)
|
53
|
+
rspec-mocks (3.1.3)
|
54
|
+
rspec-support (~> 3.1.0)
|
55
|
+
rspec-support (3.1.2)
|
56
|
+
slop (3.6.0)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
aruba
|
63
|
+
bond
|
64
|
+
cucumber
|
65
|
+
pry
|
66
|
+
pry-clipboard
|
67
|
+
pry-rescue
|
68
|
+
pry-stack_explorer
|
69
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ritchie Young
|
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,31 @@
|
|
1
|
+
# Rspec::Varys
|
2
|
+
|
3
|
+
Generate RSpec specs from intelligence gathered from doubles and spies.
|
4
|
+
|
5
|
+
This is an experiment to see if a top-down TDD work-flow can be improved by partially automating the creation of lower level specs.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'rspec-varys'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rspec-varys
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
See the [Cucumber features](https://relishapp.com/spechero/rspec-varys/docs) for examples of intended usage.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/ritchiey/rspec-varys/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
Feature: Generating an RSpec Spec from an RSpec Expectation
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a file named "spec_helper.rb" with:
|
5
|
+
"""ruby
|
6
|
+
$:.unshift File.expand_path('../../lib', File.dirname(__FILE__))
|
7
|
+
|
8
|
+
require "rspec/varys"
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
config.include RSpec::Varys::DSL
|
13
|
+
|
14
|
+
config.before(:suite) do
|
15
|
+
RSpec::Varys.reset
|
16
|
+
end
|
17
|
+
|
18
|
+
config.after(:suite) do
|
19
|
+
RSpec::Varys.print_report
|
20
|
+
end
|
21
|
+
end
|
22
|
+
"""
|
23
|
+
|
24
|
+
|
25
|
+
Scenario: For a single unmatched expectation
|
26
|
+
Given a file named "top_level_spec.rb" with:
|
27
|
+
"""ruby
|
28
|
+
require_relative 'spec_helper'
|
29
|
+
require_relative 'person'
|
30
|
+
|
31
|
+
describe "First day at work" do
|
32
|
+
|
33
|
+
it "starts with an introduction" do
|
34
|
+
boss = Person.new('Dick', 'Jones')
|
35
|
+
expect(boss).to receive(:full_name).and_return("Dick Jones")
|
36
|
+
expect(boss.welcome).to eq "Welcome to OCP, I'm Dick Jones"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
"""
|
41
|
+
And a file named "person.rb" with:
|
42
|
+
"""ruby
|
43
|
+
class Person
|
44
|
+
|
45
|
+
def initialize(firstname, lastname)
|
46
|
+
end
|
47
|
+
|
48
|
+
def welcome
|
49
|
+
"Welcome to OCP, I'm #{full_name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
"""
|
54
|
+
|
55
|
+
When I run `rspec top_level_spec.rb`
|
56
|
+
Then it should pass with:
|
57
|
+
"""
|
58
|
+
Specs have been generated based on mocks you aren't currently testing.
|
59
|
+
"""
|
60
|
+
And the file "generated_specs/person_spec.rb" should contain:
|
61
|
+
"""
|
62
|
+
describe Person do
|
63
|
+
|
64
|
+
describe "#full_name" do
|
65
|
+
|
66
|
+
it "returns the correct value" do
|
67
|
+
confirm(subject).can receive(:full_name).and_return("Dick Jones")
|
68
|
+
instance = described_class.new
|
69
|
+
expect(instance.full_name).to eq("Dick Jones")
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
"""
|
76
|
+
|
77
|
+
|
78
|
+
Scenario: For two unmatched expectations on the same class
|
79
|
+
Given a file named "top_level_spec.rb" with:
|
80
|
+
"""ruby
|
81
|
+
require_relative 'spec_helper'
|
82
|
+
require_relative 'person'
|
83
|
+
|
84
|
+
describe "First day at work" do
|
85
|
+
|
86
|
+
it "starts with an introduction" do
|
87
|
+
boss = Person.new('Dick', 'Jones')
|
88
|
+
expect(boss).to receive(:full_name).and_return("Dick Jones")
|
89
|
+
expect(boss).to receive(:title).and_return("Vice President")
|
90
|
+
expect(boss.welcome).to eq "Welcome to OCP, I'm Vice President Dick Jones"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
"""
|
95
|
+
And a file named "person.rb" with:
|
96
|
+
"""ruby
|
97
|
+
class Person
|
98
|
+
|
99
|
+
def initialize(firstname, lastname)
|
100
|
+
end
|
101
|
+
|
102
|
+
def welcome
|
103
|
+
"Welcome to OCP, I'm #{title} #{full_name}"
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
"""
|
108
|
+
|
109
|
+
When I run `rspec top_level_spec.rb`
|
110
|
+
Then it should pass with:
|
111
|
+
"""
|
112
|
+
Specs have been generated based on mocks you aren't currently testing.
|
113
|
+
"""
|
114
|
+
And the file "generated_specs/person_spec.rb" should contain:
|
115
|
+
"""
|
116
|
+
describe Person do
|
117
|
+
|
118
|
+
describe "#title" do
|
119
|
+
|
120
|
+
it "returns the correct value" do
|
121
|
+
confirm(subject).can receive(:title).and_return("Vice President")
|
122
|
+
instance = described_class.new
|
123
|
+
expect(instance.title).to eq("Vice President")
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#full_name" do
|
129
|
+
|
130
|
+
it "returns the correct value" do
|
131
|
+
confirm(subject).can receive(:full_name).and_return("Dick Jones")
|
132
|
+
instance = described_class.new
|
133
|
+
expect(instance.full_name).to eq("Dick Jones")
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
"""
|
140
|
+
|
141
|
+
Scenario: For one matched and one unmatched expectation
|
142
|
+
Given a file named "top_level_spec.rb" with:
|
143
|
+
"""ruby
|
144
|
+
require_relative 'spec_helper'
|
145
|
+
require_relative 'person'
|
146
|
+
|
147
|
+
describe "First day at work" do
|
148
|
+
|
149
|
+
it "starts with an introduction" do
|
150
|
+
boss = Person.new('Dick', 'Jones')
|
151
|
+
expect(boss).to receive(:full_name).and_return("Dick Jones")
|
152
|
+
expect(boss).to receive(:title).and_return("Vice President")
|
153
|
+
expect(boss.welcome).to eq "Welcome to OCP, I'm Vice President Dick Jones"
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
describe Person do
|
159
|
+
|
160
|
+
subject { described_class.new('Dick', 'Jones') }
|
161
|
+
|
162
|
+
describe "#full_name" do
|
163
|
+
|
164
|
+
it "returns the correct value" do
|
165
|
+
confirm(subject).can receive(:full_name).and_return("Dick Jones")
|
166
|
+
# ...
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
"""
|
174
|
+
And a file named "person.rb" with:
|
175
|
+
"""ruby
|
176
|
+
class Person
|
177
|
+
|
178
|
+
def initialize(firstname, lastname)
|
179
|
+
end
|
180
|
+
|
181
|
+
def welcome
|
182
|
+
"Welcome to OCP, I'm #{title} #{full_name}"
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
"""
|
187
|
+
|
188
|
+
When I run `rspec top_level_spec.rb`
|
189
|
+
Then it should pass with:
|
190
|
+
"""
|
191
|
+
Specs have been generated based on mocks you aren't currently testing.
|
192
|
+
"""
|
193
|
+
And the file "generated_specs/person_spec.rb" should contain:
|
194
|
+
"""
|
195
|
+
describe Person do
|
196
|
+
|
197
|
+
describe "#title" do
|
198
|
+
|
199
|
+
it "returns the correct value" do
|
200
|
+
confirm(subject).can receive(:title).and_return("Vice President")
|
201
|
+
instance = described_class.new
|
202
|
+
expect(instance.title).to eq("Vice President")
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
"""
|
209
|
+
|
data/features/readme.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
*Everything should be built top-down, except the first time - Alan
|
2
|
+
Perlis*
|
3
|
+
|
4
|
+
RSpec-Varys automatically generates RSpec specs from your mocked methods each time your suite is run.
|
5
|
+
|
6
|
+
This enables you to build your program from the top-down (or outside-in if
|
7
|
+
your prefer) without having to manually keep track of which mocks have
|
8
|
+
been validated.
|
9
|
+
|
10
|
+
Available on [Github](https://github.com/ritchiey/rspec-varys)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
data/lib/rspec/varys.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require "rspec/varys/version"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Varys
|
6
|
+
module DSL
|
7
|
+
|
8
|
+
def confirm(object)
|
9
|
+
Confirmation.new(object)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Confirmation
|
13
|
+
|
14
|
+
def initialize(object)
|
15
|
+
@object = object
|
16
|
+
end
|
17
|
+
|
18
|
+
def can(ability)
|
19
|
+
@ability = ability
|
20
|
+
RSpec::Varys.confirmed_messages << to_expectation
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def to_expectation
|
26
|
+
{
|
27
|
+
class_name: class_name,
|
28
|
+
message: message,
|
29
|
+
args: [],
|
30
|
+
return_value: "Dick Jones"
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def class_name
|
35
|
+
@object.class.name
|
36
|
+
end
|
37
|
+
|
38
|
+
def message
|
39
|
+
@ability.instance_variable_get('@message')
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
class RSpec::Mocks::Proxy
|
49
|
+
|
50
|
+
alias_method :old_message_received, :message_received
|
51
|
+
|
52
|
+
def message_received(message, *args, &block)
|
53
|
+
old_message_received(message, *args, &block).tap do |return_value|
|
54
|
+
RSpec::Varys.record object, message, args, block, return_value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
module RSpec::Varys
|
62
|
+
|
63
|
+
def self.confirmed_messages
|
64
|
+
@confirmed_messages
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.recorded_messages
|
68
|
+
@recorded_messages
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.generated_specs
|
72
|
+
@generated_specs ||= generate_specs
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.reset
|
76
|
+
@recorded_messages = []
|
77
|
+
@generated_specs = nil
|
78
|
+
@confirmed_messages = []
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.record(object, message, args, block, return_value)
|
82
|
+
@recorded_messages << {
|
83
|
+
class_name: object.class.name,
|
84
|
+
message: message,
|
85
|
+
args: args,
|
86
|
+
return_value: return_value
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.generate_specs
|
91
|
+
{}.tap do |generated_specs|
|
92
|
+
unconfirmed_messages.each do |s|
|
93
|
+
generated_specs[s[:class_name]] ||= []
|
94
|
+
generated_specs[s[:class_name]] << generate_spec(s)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def self.generate_spec(s)
|
101
|
+
<<-GENERATED
|
102
|
+
describe "##{s[:message]}" do
|
103
|
+
|
104
|
+
it "returns the correct value" do
|
105
|
+
confirm(subject).can receive(:#{s[:message]}).and_return(#{serialize s[:return_value]})
|
106
|
+
instance = described_class.new
|
107
|
+
expect(instance.#{s[:message]}).to eq(#{serialize s[:return_value]})
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
GENERATED
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.print_report
|
116
|
+
dest_path = "generated_specs"
|
117
|
+
FileUtils.mkdir_p dest_path
|
118
|
+
generated_specs.each do |class_name, specs|
|
119
|
+
File.open("#{dest_path}/#{underscore class_name}_spec.rb", 'w') do |file|
|
120
|
+
file.write "describe #{class_name} do\n\n"
|
121
|
+
specs.each do |spec|
|
122
|
+
file.write(spec)
|
123
|
+
end
|
124
|
+
file.write "end"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
puts "Specs have been generated based on mocks you aren't currently testing."
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.unconfirmed_messages
|
131
|
+
recorded_messages - confirmed_messages
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.underscore(camel_cased_word)
|
135
|
+
camel_cased_word.downcase
|
136
|
+
end
|
137
|
+
|
138
|
+
# Attempt to recreate the source-code to represent this argument in the setup
|
139
|
+
# for our generated spec.
|
140
|
+
def self.serialize(arg)
|
141
|
+
if %w(Array Hash Float Fixnum String).include? arg.class.name
|
142
|
+
arg.pretty_inspect.chop
|
143
|
+
else
|
144
|
+
guess_constructor arg
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Don't recognise the type so we don't know how to recreate it
|
149
|
+
# in source code. So we'll take a guess at what might work and
|
150
|
+
# let the user fix it up if necessary.
|
151
|
+
def self.guess_constructor(arg)
|
152
|
+
"#{arg.class.name}.new(#{serialize(arg.to_s)})"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
data/rspec-varys.gemspec
ADDED
@@ -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/varys/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-varys"
|
8
|
+
spec.version = Rspec::Varys::VERSION
|
9
|
+
spec.authors = ["Ritchie Young"]
|
10
|
+
spec.email = ["ritchiey@gmail.com"]
|
11
|
+
spec.summary = %q{Generate RSpec specs from intelligence gathered from doubles and spies.}
|
12
|
+
spec.description = %q{Automatically track which assumptions you've made in the form or mocks and stubs actually work.}
|
13
|
+
spec.homepage = "https://github.com/ritchiey/rspec-varys"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", '~> 10.4', ">= 10.4"
|
23
|
+
spec.add_development_dependency "rspec", '~> 3.1', ">= 3.1.0"
|
24
|
+
spec.add_development_dependency "cucumber", '~> 1.3', ">= 1.3.15"
|
25
|
+
spec.add_development_dependency "aruba", '~> 0.6', '>= 0.6.2'
|
26
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rspec/varys'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
class Person
|
6
|
+
|
7
|
+
def initialize(firstname, lastname)
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def welcome
|
12
|
+
"Welcome to OCP, I'm #{full_name}"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe RSpec::Varys do
|
18
|
+
|
19
|
+
describe ".unconfirmed_messages" do
|
20
|
+
|
21
|
+
it "returns the messages that don't already have specs" do
|
22
|
+
expect(described_class).to receive(:confirmed_messages).and_return([
|
23
|
+
{ class_name: 'Person', message: :full_name, args: [], return_value: "Dick Jones" }
|
24
|
+
])
|
25
|
+
expect(described_class).to receive(:recorded_messages).and_return([
|
26
|
+
{:class_name=>"Person", :message=>:full_name, :args=>[], :return_value=>"Dick Jones"},
|
27
|
+
{ class_name: 'Object', message: :a_message, args: [:a_parameter], return_value: 42 }
|
28
|
+
])
|
29
|
+
expect(described_class.unconfirmed_messages).to match_array([
|
30
|
+
{ class_name: 'Object', message: :a_message, args: [:a_parameter], return_value: 42 }
|
31
|
+
])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".confirmed_messages" do
|
36
|
+
|
37
|
+
include RSpec::Varys::DSL
|
38
|
+
|
39
|
+
it "returns a list of expectations that have been satisfied" do
|
40
|
+
confirm(Person.new 'Dick', 'Jones').can receive(:full_name).and_return("Dick Jones")
|
41
|
+
expect(described_class.confirmed_messages).to match_array([{
|
42
|
+
class_name: 'Person',
|
43
|
+
message: :full_name,
|
44
|
+
args: [],
|
45
|
+
return_value: "Dick Jones"
|
46
|
+
}])
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
it "records the messages sent to a spy" do
|
52
|
+
described_class.reset
|
53
|
+
|
54
|
+
o = Object.new
|
55
|
+
expect(o).to receive(:a_message).with(:a_parameter).and_return(42)
|
56
|
+
o.a_message(:a_parameter)
|
57
|
+
|
58
|
+
expect(described_class.recorded_messages).to match_array([{
|
59
|
+
class_name: 'Object',
|
60
|
+
message: :a_message,
|
61
|
+
args: [:a_parameter],
|
62
|
+
return_value: 42
|
63
|
+
}])
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
context "given the test-suite calls a mocked method" do
|
68
|
+
|
69
|
+
let(:expected_spec) do
|
70
|
+
<<GENERATED
|
71
|
+
describe "#full_name" do
|
72
|
+
|
73
|
+
it "returns the correct value" do
|
74
|
+
confirm(subject).can receive(:full_name).and_return("Dick Jones")
|
75
|
+
instance = described_class.new
|
76
|
+
expect(instance.full_name).to eq("Dick Jones")
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
GENERATED
|
82
|
+
end
|
83
|
+
|
84
|
+
before do
|
85
|
+
described_class.reset
|
86
|
+
|
87
|
+
dick = Person.new('Dick', 'Jones')
|
88
|
+
expect(dick).to receive(:full_name).and_return("Dick Jones")
|
89
|
+
expect(dick.welcome).to eq "Welcome to OCP, I'm Dick Jones"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "can generate required specs" do
|
93
|
+
# did it correctly record the method called
|
94
|
+
expect(described_class.recorded_messages).to match_array(
|
95
|
+
[
|
96
|
+
{
|
97
|
+
class_name: 'Person',
|
98
|
+
message: :full_name,
|
99
|
+
args: [],
|
100
|
+
return_value: "Dick Jones"
|
101
|
+
}
|
102
|
+
]
|
103
|
+
)
|
104
|
+
|
105
|
+
# did it generate an in-memory version of the specs?
|
106
|
+
expect(described_class.generated_specs).to eq('Person' => [ expected_spec ])
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-varys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ritchie Young
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-21 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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.4'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '10.4'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '10.4'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.4'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.1'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.1.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.1'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.1.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: cucumber
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1.3'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.15
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.3'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.3.15
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: aruba
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0.6'
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.6.2
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.6'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 0.6.2
|
107
|
+
description: Automatically track which assumptions you've made in the form or mocks
|
108
|
+
and stubs actually work.
|
109
|
+
email:
|
110
|
+
- ritchiey@gmail.com
|
111
|
+
executables: []
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- ".gitignore"
|
116
|
+
- ".ruby-version"
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- features/generating_specs.feature
|
123
|
+
- features/readme.md
|
124
|
+
- features/support/env.rb
|
125
|
+
- lib/rspec/varys.rb
|
126
|
+
- lib/rspec/varys/version.rb
|
127
|
+
- rspec-varys.gemspec
|
128
|
+
- spec/rspec/varys_spec.rb
|
129
|
+
homepage: https://github.com/ritchiey/rspec-varys
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.2.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Generate RSpec specs from intelligence gathered from doubles and spies.
|
153
|
+
test_files:
|
154
|
+
- features/generating_specs.feature
|
155
|
+
- features/readme.md
|
156
|
+
- features/support/env.rb
|
157
|
+
- spec/rspec/varys_spec.rb
|
158
|
+
has_rdoc:
|