rspec-varys 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1ee4c82227c770124d98e6ea57320b37e2dbceb
4
- data.tar.gz: bc60a41dc4f3ea42206f83a601170c20cc98cfae
3
+ metadata.gz: ed3afd0bea1b08e5d740b899cf61552898a3f087
4
+ data.tar.gz: 1fbc0f54564c50925894c68f3afbfdb6ba0b531e
5
5
  SHA512:
6
- metadata.gz: 2609cf4e8e4b3f70bb97beb03a602bbee9ea7c7785f5bb65c6b4585cf9759da9cb1183b4210ee0ef2a317761d7b69b7f30c280a3c62dd6d29464fb02396d2fd0
7
- data.tar.gz: 8ffd607d581171121703f2090f6870e2efb5a323f02260e2ceb86203edf052defe274d38e9150eb644ca1a2e48596e80e864943913c547cd39cb4bcfb8e80b43
6
+ metadata.gz: e6df64e6d021530e67876ed6e78fd71a4ea319555e63e9b48f0eb1ba3b4486ace053181a26ddbde1220d0eb101c6bf253e6a50e9ae31092129c8cfc9936bf1a7
7
+ data.tar.gz: 297d03dc4b940c3d71a0c4f10062269c52394c015285e66c566213257c279516fdc37280be6a1f9dc70802591bb4bf0678e0bab85285cb9ec4f9e407e293a8d4
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'pry-rescue'
data/Gemfile.lock CHANGED
@@ -1,3 +1,8 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rspec-varys (0.0.2)
5
+
1
6
  GEM
2
7
  remote: https://rubygems.org/
3
8
  specs:
@@ -5,13 +10,9 @@ GEM
5
10
  childprocess (>= 0.3.6)
6
11
  cucumber (>= 1.1.1)
7
12
  rspec-expectations (>= 2.7.0)
8
- binding_of_caller (0.7.2)
9
- debug_inspector (>= 0.0.1)
10
- bond (0.5.1)
11
13
  builder (3.2.2)
12
14
  childprocess (0.5.5)
13
15
  ffi (~> 1.0, >= 1.0.11)
14
- clipboard (1.0.5)
15
16
  coderay (1.1.0)
16
17
  cucumber (1.3.15)
17
18
  builder (>= 2.1.2)
@@ -19,7 +20,6 @@ GEM
19
20
  gherkin (~> 2.12)
20
21
  multi_json (>= 1.7.5, < 2.0)
21
22
  multi_test (>= 0.1.1)
22
- debug_inspector (0.0.2)
23
23
  diff-lcs (1.2.5)
24
24
  ffi (1.9.6)
25
25
  gherkin (2.12.2)
@@ -32,15 +32,10 @@ GEM
32
32
  coderay (~> 1.1.0)
33
33
  method_source (~> 0.8.1)
34
34
  slop (~> 3.4)
35
- pry-clipboard (0.1.1)
36
- clipboard
37
- pry
38
35
  pry-rescue (1.4.1)
39
36
  interception (>= 0.5)
40
37
  pry
41
- pry-stack_explorer (0.4.9.1)
42
- binding_of_caller (>= 0.7)
43
- pry (>= 0.9.11)
38
+ rake (10.4.2)
44
39
  rspec (3.1.0)
45
40
  rspec-core (~> 3.1.0)
46
41
  rspec-expectations (~> 3.1.0)
@@ -59,11 +54,10 @@ PLATFORMS
59
54
  ruby
60
55
 
61
56
  DEPENDENCIES
62
- aruba
63
- bond
64
- cucumber
65
- pry
66
- pry-clipboard
57
+ aruba (~> 0.6, >= 0.6.2)
58
+ bundler (~> 1.6)
59
+ cucumber (~> 1.3, >= 1.3.15)
67
60
  pry-rescue
68
- pry-stack_explorer
69
- rspec
61
+ rake (~> 10.4, >= 10.4)
62
+ rspec (~> 3.1, >= 3.1.0)
63
+ rspec-varys!
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/rspec-varys.svg)](http://badge.fury.io/rb/rspec-varys)
2
+
1
3
  # Rspec::Varys
2
4
 
3
5
  Generate RSpec specs from intelligence gathered from doubles and spies.
@@ -207,3 +207,67 @@ Feature: Generating an RSpec Spec from an RSpec Expectation
207
207
  end
208
208
  """
209
209
 
210
+ Scenario: For an expectation with parameters
211
+ Given a file named "top_level_spec.rb" with:
212
+ """ruby
213
+ require_relative 'spec_helper'
214
+ require_relative 'person'
215
+
216
+ describe Person do
217
+
218
+ subject { described_class.new('Dick', 'Jones') }
219
+
220
+ describe "#full_name" do
221
+
222
+ it "returns the correct value" do
223
+ confirm(subject).can receive(:full_name).and_return("Dick Jones")
224
+ expect(subject).to receive(:join_names).with("Dick", "Jones").and_return("Dick Jones")
225
+ subject.full_name
226
+ end
227
+
228
+ end
229
+
230
+ end
231
+
232
+ """
233
+ And a file named "person.rb" with:
234
+ """ruby
235
+ class Person
236
+
237
+ def initialize(first_name, last_name)
238
+ @first_name = first_name
239
+ @last_name = last_name
240
+ end
241
+
242
+ def welcome
243
+ "Welcome to OCP, I'm #{full_name}"
244
+ end
245
+
246
+ def full_name
247
+ join_names(@first_name, @last_name)
248
+ end
249
+
250
+ end
251
+ """
252
+
253
+ When I run `rspec top_level_spec.rb`
254
+ Then it should pass with:
255
+ """
256
+ Specs have been generated based on mocks you aren't currently testing.
257
+ """
258
+ And the file "generated_specs/person_spec.rb" should contain:
259
+ """
260
+ describe Person do
261
+
262
+ describe "#join_names" do
263
+
264
+ it "returns the correct value" do
265
+ confirm(subject).can receive(:join_names).with("Dick", "Jones").and_return("Dick Jones")
266
+ instance = described_class.new
267
+ expect(instance.join_names("Dick", "Jones")).to eq("Dick Jones")
268
+ end
269
+
270
+ end
271
+
272
+ end
273
+ """
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Varys
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/lib/rspec/varys.rb CHANGED
@@ -102,9 +102,9 @@ module RSpec::Varys
102
102
  describe "##{s[:message]}" do
103
103
 
104
104
  it "returns the correct value" do
105
- confirm(subject).can receive(:#{s[:message]}).and_return(#{serialize s[:return_value]})
105
+ confirm(subject).can receive(:#{s[:message]})#{with_parameters(s)}.and_return(#{serialize s[:return_value]})
106
106
  instance = described_class.new
107
- expect(instance.#{s[:message]}).to eq(#{serialize s[:return_value]})
107
+ expect(instance.#{s[:message]}#{parameters(s)}).to eq(#{serialize s[:return_value]})
108
108
  end
109
109
 
110
110
  end
@@ -112,6 +112,26 @@ module RSpec::Varys
112
112
  GENERATED
113
113
  end
114
114
 
115
+ def self.with_parameters(spec)
116
+ if spec[:args].length > 0
117
+ %Q[.with(#{params spec[:args]})]
118
+ else
119
+ ""
120
+ end
121
+ end
122
+
123
+ def self.params(args)
124
+ args.map{|a| serialize(a)}.join(", ")
125
+ end
126
+
127
+ def self.parameters(spec)
128
+ if spec[:args].length > 0
129
+ %Q[(#{params spec[:args]})]
130
+ else
131
+ ""
132
+ end
133
+ end
134
+
115
135
  def self.print_report
116
136
  dest_path = "generated_specs"
117
137
  FileUtils.mkdir_p dest_path
@@ -2,17 +2,21 @@ require 'rspec'
2
2
  require 'rspec/varys'
3
3
  require 'pry'
4
4
 
5
- class Person
5
+ class Person
6
6
 
7
- def initialize(firstname, lastname)
8
-
9
- end
7
+ def initialize(first_name, last_name)
8
+ @first_name = first_name
9
+ @last_name = last_name
10
+ end
10
11
 
11
- def welcome
12
- "Welcome to OCP, I'm #{full_name}"
13
- end
12
+ def welcome
13
+ "Welcome to OCP, I'm #{full_name}"
14
+ end
14
15
 
16
+ def full_name
17
+ join_names(@first_name, @last_name)
15
18
  end
19
+ end
16
20
 
17
21
  describe RSpec::Varys do
18
22
 
@@ -39,11 +43,11 @@ describe RSpec::Varys do
39
43
  it "returns a list of expectations that have been satisfied" do
40
44
  confirm(Person.new 'Dick', 'Jones').can receive(:full_name).and_return("Dick Jones")
41
45
  expect(described_class.confirmed_messages).to match_array([{
42
- class_name: 'Person',
43
- message: :full_name,
44
- args: [],
45
- return_value: "Dick Jones"
46
- }])
46
+ class_name: 'Person',
47
+ message: :full_name,
48
+ args: [],
49
+ return_value: "Dick Jones"
50
+ }])
47
51
  end
48
52
 
49
53
  end
@@ -65,9 +69,10 @@ describe RSpec::Varys do
65
69
 
66
70
 
67
71
  context "given the test-suite calls a mocked method" do
72
+ context "with no paramters" do
68
73
 
69
- let(:expected_spec) do
70
- <<GENERATED
74
+ let(:expected_spec) do
75
+ <<GENERATED
71
76
  describe "#full_name" do
72
77
 
73
78
  it "returns the correct value" do
@@ -79,34 +84,84 @@ describe RSpec::Varys do
79
84
  end
80
85
 
81
86
  GENERATED
87
+ end
88
+
89
+ let(:recognised_specs) {
90
+ [
91
+ {
92
+ class_name: 'Person',
93
+ message: :full_name,
94
+ args: [],
95
+ return_value: "Dick Jones"
96
+ }
97
+ ]
98
+ }
99
+
100
+ before do
101
+ described_class.reset
102
+
103
+ dick = Person.new('Dick', 'Jones')
104
+ expect(dick).to receive(:full_name).and_return("Dick Jones")
105
+ expect(dick.welcome).to eq "Welcome to OCP, I'm Dick Jones"
106
+ end
107
+
108
+ it "can generate required specs" do
109
+ # did it correctly record the method called
110
+ expect(described_class.recorded_messages).to match_array(recognised_specs)
111
+
112
+ # did it generate an in-memory version of the specs?
113
+ expect(described_class.generated_specs).to eq('Person' => [ expected_spec ])
114
+
115
+ end
116
+
82
117
  end
83
118
 
84
- before do
85
- described_class.reset
119
+ context "with parameters" do
120
+
121
+ let(:expected_spec) do
122
+ <<GENERATED
123
+ describe "#join_names" do
86
124
 
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"
125
+ it "returns the correct value" do
126
+ confirm(subject).can receive(:join_names).with("Dick", "Jones").and_return("Dick Jones")
127
+ instance = described_class.new
128
+ expect(instance.join_names("Dick", "Jones")).to eq("Dick Jones")
90
129
  end
91
130
 
92
- it "can generate required specs" do
93
- # did it correctly record the method called
94
- expect(described_class.recorded_messages).to match_array(
131
+ end
132
+
133
+ GENERATED
134
+ end
135
+
136
+ let(:recognised_specs) {
95
137
  [
96
138
  {
97
139
  class_name: 'Person',
98
- message: :full_name,
99
- args: [],
140
+ message: :join_names,
141
+ args: ["Dick", "Jones"],
100
142
  return_value: "Dick Jones"
101
143
  }
102
144
  ]
103
- )
145
+ }
104
146
 
105
- # did it generate an in-memory version of the specs?
106
- expect(described_class.generated_specs).to eq('Person' => [ expected_spec ])
147
+ before do
148
+ described_class.reset
107
149
 
108
- end
150
+ dick = Person.new('Dick', 'Jones')
151
+ expect(dick).to receive(:join_names).with("Dick", "Jones").and_return("Dick Jones")
152
+ expect(dick.welcome).to eq "Welcome to OCP, I'm Dick Jones"
153
+ end
109
154
 
155
+ it "can generate required specs" do
156
+ # did it correctly record the method called
157
+ expect(described_class.recorded_messages).to match_array(recognised_specs)
158
+
159
+ # did it generate an in-memory version of the specs?
160
+ expect(described_class.generated_specs).to eq('Person' => [ expected_spec ])
161
+
162
+ end
163
+
164
+ end
110
165
  end
111
166
 
112
167
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-varys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ritchie Young
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler