rspec-junklet 2.1.3 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/Gemfile.lock +19 -9
- data/lib/rspec/junklet/formatter.rb +5 -0
- data/lib/rspec/junklet/junk.rb +14 -13
- data/lib/rspec/junklet/version.rb +1 -1
- data/rspec-junklet.gemspec +1 -0
- data/spec/lib/rspec/junklet/junk_spec.rb +181 -109
- data/spec/lib/rspec/junklet/junklet_spec.rb +24 -25
- data/spec/spec_helper.rb +37 -0
- data/spec/support/banner.rb +10 -0
- metadata +33 -18
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZTk1ZjllMmM4ZGJhNTI1YWU1OTA0NzNlY2FiNTk2ODQxYTNiOGY2Yw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d86599950fe1c28302e71d4679251be2495ef794
|
4
|
+
data.tar.gz: d8696cb846ae80ed7db3658643f65160b566f6b8
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OWQ5MmMxNDZkYmZlOGE1MTEwNDBlNmZiYzY3ZmMyNDQwOTIwM2JmZjIzM2Q4
|
11
|
-
NjFkZGNjNzA0NzJhY2Y0MTllYTYzMGNhM2M3MTQzYTlmZmExN2I=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Y2M0NWIzYmM1MDc0ZTUwOGQ4MjUyNGQxNDYwYmM4NzA1ODJiN2E4OWI2NjU1
|
14
|
-
M2EzMzg1OTZhNzAyYzNlMTRmMGZiZmVmZjA4NjBjZjZiODZiNzhlN2Q1ZDQw
|
15
|
-
ZDRmYzZhYTQwMmZlNTkzNTE4ODY0NmViYzY5ZmVhOWU1NThmYjc=
|
6
|
+
metadata.gz: 661c26d2f4d0317fd54bb28d4b581fd5a93d892036cf5b1633fdbd8bf42bbf5853c0ad97eb0550199ce8944edac88569d6b260eabdd4ffbf8d68caf869141e80
|
7
|
+
data.tar.gz: 85287ab4a12a9c6eb013f17b65a43a7dcf75550c92c56ce241efd6a71152b1626af96e810c10f2938fb4a4b57518de541395f1cffde754e43286a582707c19ec
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-junklet (2.
|
4
|
+
rspec-junklet (2.2.0)
|
5
5
|
rspec (>= 2.0, < 4.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
byebug (9.0.6)
|
10
11
|
coderay (1.1.0)
|
11
12
|
diff-lcs (1.2.5)
|
12
13
|
method_source (0.8.2)
|
@@ -15,14 +16,19 @@ GEM
|
|
15
16
|
method_source (~> 0.8.1)
|
16
17
|
slop (~> 3.4)
|
17
18
|
rake (10.4.2)
|
18
|
-
rspec (
|
19
|
-
rspec-core (~>
|
20
|
-
rspec-expectations (~>
|
21
|
-
rspec-mocks (~>
|
22
|
-
rspec-core (
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
rspec (3.5.0)
|
20
|
+
rspec-core (~> 3.5.0)
|
21
|
+
rspec-expectations (~> 3.5.0)
|
22
|
+
rspec-mocks (~> 3.5.0)
|
23
|
+
rspec-core (3.5.2)
|
24
|
+
rspec-support (~> 3.5.0)
|
25
|
+
rspec-expectations (3.5.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.5.0)
|
28
|
+
rspec-mocks (3.5.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.5.0)
|
31
|
+
rspec-support (3.5.0)
|
26
32
|
slop (3.6.0)
|
27
33
|
|
28
34
|
PLATFORMS
|
@@ -30,6 +36,10 @@ PLATFORMS
|
|
30
36
|
|
31
37
|
DEPENDENCIES
|
32
38
|
bundler (~> 1.7)
|
39
|
+
byebug (~> 9.0)
|
33
40
|
pry (~> 0.10)
|
34
41
|
rake (~> 10.0)
|
35
42
|
rspec-junklet!
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.14.6
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Junklet
|
3
|
+
# Formatter.new(input) receives the generated junk, and #format returns the
|
4
|
+
# input already formatted. You don't have to inherit from this class; as
|
5
|
+
# long as your class accepts one argument to .new and responds to #format
|
6
|
+
# you're a formatter. Inheriting from Formatter means you already have a
|
7
|
+
# basic implementation, however.
|
3
8
|
class Formatter
|
4
9
|
attr_reader :input
|
5
10
|
|
data/lib/rspec/junklet/junk.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
require_relative 'formatter'
|
2
4
|
|
3
5
|
module RSpec
|
@@ -67,14 +69,15 @@ module RSpec
|
|
67
69
|
type = args.shift
|
68
70
|
opts = args.last || {}
|
69
71
|
|
70
|
-
excluder =
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
else
|
72
|
+
excluder = case opts[:exclude]
|
73
|
+
when Proc
|
74
|
+
opts[:exclude]
|
75
|
+
when Enumerator
|
76
|
+
->(x) { opts[:exclude].include?(x) }
|
77
|
+
when nil
|
77
78
|
->(x) { false }
|
79
|
+
else
|
80
|
+
->(x) { Array(opts[:exclude]).include?(x) }
|
78
81
|
end
|
79
82
|
|
80
83
|
formatter = case opts[:format]
|
@@ -83,11 +86,9 @@ module RSpec
|
|
83
86
|
when :int
|
84
87
|
->(x) { x.to_i }
|
85
88
|
when Class
|
86
|
-
raise "Formatter class must implement #format method" unless
|
87
|
-
opts[:format].new(0).respond_to? :format
|
88
89
|
->(x) { opts[:format].new(x).format }
|
89
90
|
when String
|
90
|
-
|
91
|
+
->(x) { sprintf(opts[:format], *Array(x)) }
|
91
92
|
when Proc
|
92
93
|
opts[:format]
|
93
94
|
else
|
@@ -133,10 +134,10 @@ module RSpec
|
|
133
134
|
end
|
134
135
|
|
135
136
|
val = if repeat.zero?
|
136
|
-
|
137
|
+
generate_junk(generator, formatter, excluder)
|
137
138
|
else
|
138
139
|
repeat.times.map {
|
139
|
-
|
140
|
+
generate_junk(generator, formatter, excluder)
|
140
141
|
}
|
141
142
|
end
|
142
143
|
val
|
@@ -153,7 +154,7 @@ module RSpec
|
|
153
154
|
|
154
155
|
private
|
155
156
|
|
156
|
-
def
|
157
|
+
def generate_junk(generator, formatter, excluder)
|
157
158
|
begin
|
158
159
|
v = formatter.call(generator.call)
|
159
160
|
end while excluder.call(v)
|
data/rspec-junklet.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "byebug", "~> 9.0"
|
22
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
24
|
spec.add_development_dependency "pry", "~> 0.10"
|
24
25
|
spec.add_dependency "rspec", [">= 2.0", "< 4.0"]
|
@@ -1,196 +1,268 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require PROJECT_ROOT + 'lib/rspec/junklet/junk'
|
2
|
+
require PROJECT_ROOT + 'lib/rspec/junklet/junk.rb'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
include ::RSpec::Junklet::Junk
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.extend(RSpec::Junklet::Junk) # This lets us say junk() in describes and contexts
|
6
|
+
config.include(RSpec::Junklet::Junk) # This lets us say junk() in describes and contexts
|
8
7
|
end
|
9
8
|
|
10
|
-
describe
|
11
|
-
let(:junk) { subject.junk }
|
9
|
+
describe ::RSpec::Junklet::Junk do
|
12
10
|
let(:hex_regex) { /^[0-9a-f]+$/ }
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
describe "#junk" do
|
13
|
+
it "is a hexadecimal string" do
|
14
|
+
expect(junk).to match hex_regex
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defaults to 32 characters" do
|
18
|
+
expect(junk.size).to eq(32)
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
|
21
|
+
it "is random each time" do
|
22
|
+
expect(junk).to_not eq(junk)
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
describe "#junk(size)" do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
specify { expect(junk.size).to eq(14) }
|
27
|
+
it "emits exactly (size) characters" do
|
28
|
+
expect(junk(14).size).to eq 14
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
|
-
describe "#junk(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
describe "#junk(:int)" do
|
33
|
+
it "generates a Fixnum" do
|
34
|
+
expect(junk(:int)).to be_a Integer
|
35
|
+
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
it "constrains the value" do
|
36
|
-
expect([3,4,5]).to include(junk)
|
37
|
-
end
|
38
|
-
end
|
37
|
+
context "with min or max option" do
|
38
|
+
let(:val) { junk :int, min: 3, max: 5 }
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
expect((1000..9999)).to include(junk)
|
44
|
-
end
|
40
|
+
it "constrains the value" do
|
41
|
+
expect(val).to be >= 3
|
42
|
+
expect(val).to be <= 5
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
context "
|
49
|
-
let(:
|
46
|
+
context "with size option" do
|
47
|
+
let(:val) { junk :int, size: 4 }
|
50
48
|
|
51
|
-
it "
|
52
|
-
expect(
|
49
|
+
it "generates a number with that many digits (no leading zeroes)" do
|
50
|
+
expect(val).to be >= 1000
|
51
|
+
expect(val).to be <= 9999
|
53
52
|
end
|
54
53
|
end
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
describe "junk(:bool)" do
|
57
|
+
let(:val) { junk :bool }
|
58
58
|
|
59
|
-
|
59
|
+
it "returns a boolean" do
|
60
|
+
expect([false, true]).to include val
|
60
61
|
end
|
62
|
+
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
+
describe "junk(<Array>)" do
|
65
|
+
let(:options) { [:a, :b, 3] }
|
66
|
+
let(:val) { junk options }
|
64
67
|
|
65
|
-
|
68
|
+
it "returns an element of the collection" do
|
69
|
+
expect(options).to include val
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
|
-
|
73
|
+
describe "junk(<Enumerable>)" do
|
74
|
+
let(:options) { (1..5) }
|
75
|
+
let(:val) { junk options }
|
76
|
+
|
77
|
+
it "returns an element of the collection" do
|
78
|
+
expect(options).to include val
|
79
|
+
end
|
80
|
+
|
81
|
+
it "calls #.to_a on the Enumerable" do
|
82
|
+
# This expectation is included to document that this happens, and could
|
83
|
+
# potentially cause a memory problem. Don't do junk (1..1_000_000_000_000)
|
84
|
+
# unless you're all done with having memory.
|
85
|
+
expect(options).to receive(:to_a).and_call_original
|
86
|
+
expect(options).to include val
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "junk(<Proc>)" do
|
91
|
+
let(:lambda) { ->{ [1,2,3].sample } }
|
92
|
+
let(:val) { junk lambda }
|
93
|
+
|
94
|
+
it "evaluates the proc" do
|
95
|
+
expect(lambda).to receive(:call).and_call_original
|
96
|
+
expect([1,2,3]).to include val
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "exclude option" do
|
101
|
+
let(:even_numbers) { [0,2,4,6,8,10] }
|
102
|
+
let(:odd_numbers) { [1,3,5,7,9] }
|
103
|
+
|
70
104
|
context "when excluding an item" do
|
71
|
-
let(:
|
105
|
+
let(:val) { junk :bool, exclude: true }
|
72
106
|
|
73
|
-
|
107
|
+
it "excludes the item" do
|
108
|
+
expect(val).to be false
|
109
|
+
end
|
74
110
|
end
|
75
111
|
|
76
|
-
context "when excluding
|
77
|
-
let(:
|
112
|
+
context "when excluding a list" do
|
113
|
+
let(:val) { junk :int, max: 10, exclude: odd_numbers }
|
78
114
|
|
79
|
-
|
115
|
+
it "excludes all of the items" do
|
116
|
+
expect(val).to be_in even_numbers
|
117
|
+
end
|
80
118
|
end
|
81
119
|
|
82
|
-
context "when excluding an
|
83
|
-
let(:
|
120
|
+
context "when excluding an enumerator" do
|
121
|
+
let(:odd_enum) { 1.step(9, 2) }
|
122
|
+
let(:val) { junk :int, max: 10, exclude: odd_enum }
|
123
|
+
|
124
|
+
it "excludes the elements of the enumerable" do
|
125
|
+
expect(val).to be_in even_numbers
|
126
|
+
end
|
84
127
|
|
85
|
-
|
128
|
+
it "does not call #.to_a on the enumerable to get the complete list" do
|
129
|
+
expect(odd_enum).to_not receive(:to_a)
|
130
|
+
expect(val).to be_in even_numbers
|
131
|
+
end
|
132
|
+
|
133
|
+
it "calls #include? on the enumerable to determine rejection" do
|
134
|
+
expect(odd_enum).to receive(:include?).at_least(:once).and_call_original
|
135
|
+
expect(val).to be_in even_numbers
|
136
|
+
end
|
86
137
|
end
|
87
138
|
|
88
139
|
context "when excluding a Proc" do
|
89
|
-
let(:
|
90
|
-
|
140
|
+
let(:generator) { [1,3,5,6].to_enum }
|
141
|
+
let(:generator_proc) { -> { generator.next } }
|
142
|
+
let(:odd_excluder_proc) { ->(x) { x % 2 == 1 } }
|
143
|
+
let(:val) { junk generator_proc, exclude: odd_excluder_proc }
|
144
|
+
|
145
|
+
it "excludes the candidate if the proc returns true" do
|
146
|
+
expect(val).to eq 6
|
147
|
+
end
|
148
|
+
|
149
|
+
it "passes the junk candidates to the proc" do
|
150
|
+
expect(odd_excluder_proc).to receive(:call).with(1).and_call_original # rejected
|
151
|
+
expect(odd_excluder_proc).to receive(:call).with(3).and_call_original # rejected
|
152
|
+
expect(odd_excluder_proc).to receive(:call).with(5).and_call_original # rejected
|
153
|
+
expect(odd_excluder_proc).to receive(:call).with(6).and_call_original # accepted
|
154
|
+
expect(val).to eq 6
|
155
|
+
end
|
91
156
|
end
|
92
157
|
end
|
93
158
|
|
94
|
-
|
159
|
+
describe "format option" do
|
95
160
|
context "when format is :string" do
|
96
|
-
|
161
|
+
it "returns the junk cast to a string" do
|
162
|
+
expect(junk [42], format: :string).to eq "42"
|
163
|
+
end
|
164
|
+
|
165
|
+
let(:item) { double }
|
166
|
+
let(:generator) { [item] }
|
167
|
+
let(:val) { junk generator, format: :string }
|
97
168
|
|
98
|
-
|
169
|
+
it "sends #to_s to the junk to convert it" do
|
170
|
+
expect(item).to receive(:to_s).and_return "42"
|
171
|
+
expect(val).to eq "42"
|
172
|
+
end
|
99
173
|
end
|
100
174
|
|
175
|
+
# Why is this even here, it never gets used...
|
101
176
|
context "when format is :int" do
|
102
|
-
|
177
|
+
it "returns the junk cast to an integer" do
|
178
|
+
expect(junk ["42"], format: :int).to eq 42
|
179
|
+
end
|
103
180
|
|
104
|
-
|
105
|
-
|
181
|
+
let(:item) { double }
|
182
|
+
let(:generator) { [item] }
|
183
|
+
let(:val) { junk generator, format: :int }
|
184
|
+
|
185
|
+
it "sends #to_i to the junk to convert it" do
|
186
|
+
expect(item).to receive(:to_i).and_return 42
|
187
|
+
expect(val).to eq 42
|
188
|
+
end
|
106
189
|
end
|
107
190
|
|
108
|
-
context "when format is a format string" do
|
109
|
-
let(:
|
191
|
+
context "when format is a sprintf-style format string" do
|
192
|
+
let(:binary_string) { junk :int, format: "%b" }
|
110
193
|
|
111
|
-
it "formats the
|
112
|
-
expect(
|
194
|
+
it "formats the generated junk with the format string" do
|
195
|
+
expect(binary_string).to match /^[01]+$/
|
113
196
|
end
|
114
|
-
end
|
115
197
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
198
|
+
context "when generator emits an array" do
|
199
|
+
let(:generator) { ->{ [2017, 1, 9] } }
|
200
|
+
let(:val) { junk generator, format: "%d-%02d-%02d" }
|
201
|
+
|
202
|
+
it "passes all of the array elements to the format string" do
|
203
|
+
expect(val).to eq "2017-01-09"
|
120
204
|
end
|
205
|
+
end
|
206
|
+
end
|
121
207
|
|
208
|
+
context "when fromat is a custom Junklet::Formatter class" do
|
209
|
+
# By inheriting from Formatter, we get new(input) for free
|
210
|
+
class HexTripler < RSpec::Junklet::Formatter
|
122
211
|
def format
|
123
|
-
"0x%02x" %
|
212
|
+
"0x%02x" % (input * 3)
|
124
213
|
end
|
125
214
|
end
|
126
215
|
|
127
|
-
let(:
|
216
|
+
let(:val) { junk [14], format: HexTripler }
|
128
217
|
|
129
|
-
it "
|
130
|
-
expect(
|
131
|
-
expect(junk).to eq("0x0c")
|
218
|
+
it "passes junk to new and calls format" do
|
219
|
+
expect(val).to eq "0x2a"
|
132
220
|
end
|
133
221
|
end
|
134
222
|
|
135
|
-
context "when format is a class that
|
223
|
+
context "when format is a any class that implements .new(junk) and #format" do
|
136
224
|
class HexDoubler
|
137
225
|
def initialize(input)
|
138
226
|
@n = input
|
139
227
|
end
|
140
228
|
|
141
|
-
def value
|
142
|
-
@n * 2
|
143
|
-
end
|
144
|
-
|
145
229
|
def format
|
146
|
-
"0x%
|
230
|
+
"0x%02x" % (@n * 2)
|
147
231
|
end
|
148
232
|
end
|
149
233
|
|
150
|
-
let(:
|
234
|
+
let(:val) { junk [14], format: HexDoubler }
|
151
235
|
|
152
|
-
it "
|
153
|
-
expect(
|
154
|
-
expect(junk).to eq("0x0018")
|
236
|
+
it "passes junk to new and calls format" do
|
237
|
+
expect(val).to eq "0x1c"
|
155
238
|
end
|
156
239
|
end
|
157
240
|
|
158
|
-
context "
|
159
|
-
|
160
|
-
def initialize(input)
|
161
|
-
end
|
241
|
+
context "when format is a Proc" do
|
242
|
+
let(:val) { junk [14], format: ->(x) { x.to_s(2) } }
|
162
243
|
|
163
|
-
|
164
|
-
|
244
|
+
it "formats the junk through the proc" do
|
245
|
+
expect(val).to eq "1110"
|
165
246
|
end
|
166
247
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
end
|
248
|
+
context "when generator emits an array" do
|
249
|
+
let(:generator) { ->{ [2017, 1, 9] } }
|
250
|
+
let(:val) { junk generator, format: ->(x) { "%d-%02d-%02d" % x } }
|
171
251
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
# expect(doubled_string.size).to eq(12) # nope, it's 6
|
176
|
-
# junk 6, format: ->(x) { x.upcase } # also returns x unmodified
|
177
|
-
|
178
|
-
context "when format is a Proc" do
|
179
|
-
let(:junk) { subject.junk [3], format: ->(x) { x * 3 } }
|
180
|
-
|
181
|
-
it "calls proc on junk value" do
|
182
|
-
expect(junk).to eq(9)
|
252
|
+
it "passes all of the array elements to the format string" do
|
253
|
+
expect(val).to eq "2017-01-09"
|
254
|
+
end
|
183
255
|
end
|
184
256
|
end
|
257
|
+
end
|
185
258
|
|
186
|
-
|
187
|
-
|
188
|
-
|
259
|
+
describe "format and exclude used together" do
|
260
|
+
let(:truth) { junk :bool, format: :string, exclude: "false" }
|
261
|
+
let(:lies) { junk :bool, format: :string, exclude: truth }
|
189
262
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
end
|
263
|
+
it "applies exclusion after formatting" do
|
264
|
+
expect(truth).to eq("true")
|
265
|
+
expect(lies).to eq("false")
|
194
266
|
end
|
195
267
|
end
|
196
268
|
end
|
@@ -1,40 +1,39 @@
|
|
1
1
|
require PROJECT_ROOT + 'lib/rspec/junklet/junklet'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.extend(RSpec::Junklet::Junklet) # This lets us say junklet() in describes and contexts
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
+
describe '.junklet' do
|
8
|
+
junklet :pigs, :cows
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
it "generates a let" do
|
11
|
+
expect(pigs).to be
|
12
|
+
expect(cows).to be
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
it "prefixes the let with its own name" do
|
16
|
+
expect(pigs).to match /^pigs_/
|
17
|
+
expect(cows).to match /^cows_/
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
it "appends 32 hex characters of random noise to make it unique" do
|
21
|
+
expect(pigs).to match /^pigs_[0-9a-f]{32}$/
|
22
|
+
expect(cows).to match /^cows_[0-9a-f]{32}$/
|
23
|
+
end
|
19
24
|
|
20
|
-
describe
|
21
|
-
|
22
|
-
expect(subject).to receive(:let).with(:pigs)
|
23
|
-
expect(subject).to receive(:let).with(:cows)
|
24
|
-
subject.junklet :pigs, :cows
|
25
|
-
end
|
25
|
+
describe "separator option" do
|
26
|
+
junklet :pigtruck, separator: '~'
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(
|
29
|
-
expect(subject).to receive(:make_junklet).with(:cow_truck, 'cow_truck', '_')
|
30
|
-
subject.junklet :pig_truck, :cow_truck
|
28
|
+
it 'uses separator instead of underscore' do
|
29
|
+
expect(pigtruck).to match /^pigtruck~/
|
31
30
|
end
|
32
31
|
|
33
|
-
context "
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
context "when junklet has underscores in its name" do
|
33
|
+
junklet :http_get_param, separator: '-'
|
34
|
+
|
35
|
+
it 'replaces underscores in junklet name as well' do
|
36
|
+
expect(http_get_param).to match /^http-get-param-/
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative PROJECT_ROOT + "lib" + "rspec" + "junklet"
|
|
6
6
|
|
7
7
|
|
8
8
|
require "pry"
|
9
|
+
require "byebug"
|
9
10
|
|
10
11
|
# Since we've kept rigidly to 80-columns, we can easily
|
11
12
|
# Do a pretty side-by-side diff here. This won't handle
|
@@ -46,3 +47,39 @@ def dump_diff(expected_lines, got_lines)
|
|
46
47
|
end
|
47
48
|
dump_footer
|
48
49
|
end
|
50
|
+
|
51
|
+
# be_in - working inverse of #cover and #include, e.g.
|
52
|
+
#
|
53
|
+
# let(:range) { (1..5) }
|
54
|
+
# let(:list) { [1,2,3,4,5] }
|
55
|
+
# let(:val) { 3 }
|
56
|
+
#
|
57
|
+
# specify { expect(range).to cover val }
|
58
|
+
# specify { expect(val).to be_in range }
|
59
|
+
# specify { expect(list).to include val }
|
60
|
+
# specify { expect(val).to be_in list }
|
61
|
+
#
|
62
|
+
# Why? Because sometimes I think reading order is important. For example, if the
|
63
|
+
# options for a command can vary and we want to assert that they contain a known
|
64
|
+
# correct value, I prefer
|
65
|
+
#
|
66
|
+
# specify { expect(options).to include value }
|
67
|
+
#
|
68
|
+
# As it is the options that are in question here. But if the list of known
|
69
|
+
# options is fixed, and the code under test returns a value that we want to
|
70
|
+
# prove is inside the list of known options, I prefer
|
71
|
+
#
|
72
|
+
# specify { expect(value).to be_in options }
|
73
|
+
#
|
74
|
+
# ...and yes, I frequently put an #in? method on Object that takes a collection,
|
75
|
+
# and simply calls collection.include?(self) internally. Again just because
|
76
|
+
# reading order.
|
77
|
+
RSpec::Matchers.define :be_in do |list|
|
78
|
+
match do |element|
|
79
|
+
list.include? element
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
84
|
+
|
85
|
+
Dir[File.join(gem_root, 'spec/support/**/*.rb')].each { |f| require f }
|
metadata
CHANGED
@@ -1,75 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-junklet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Brady
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '9.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '9.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - ~>
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '10.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - ~>
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pry
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - ~>
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '0.10'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - ~>
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0.10'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '2.0'
|
62
|
-
- - <
|
76
|
+
- - "<"
|
63
77
|
- !ruby/object:Gem::Version
|
64
78
|
version: '4.0'
|
65
79
|
type: :runtime
|
66
80
|
prerelease: false
|
67
81
|
version_requirements: !ruby/object:Gem::Requirement
|
68
82
|
requirements:
|
69
|
-
- -
|
83
|
+
- - ">="
|
70
84
|
- !ruby/object:Gem::Version
|
71
85
|
version: '2.0'
|
72
|
-
- - <
|
86
|
+
- - "<"
|
73
87
|
- !ruby/object:Gem::Version
|
74
88
|
version: '4.0'
|
75
89
|
description: Works like let for rspec, but creates unique random junk data
|
@@ -79,9 +93,8 @@ executables: []
|
|
79
93
|
extensions: []
|
80
94
|
extra_rdoc_files: []
|
81
95
|
files:
|
82
|
-
- .gitignore
|
83
|
-
- .rspec
|
84
|
-
- .ruby-version
|
96
|
+
- ".gitignore"
|
97
|
+
- ".rspec"
|
85
98
|
- Gemfile
|
86
99
|
- Gemfile.lock
|
87
100
|
- LICENSE
|
@@ -106,6 +119,7 @@ files:
|
|
106
119
|
- spec/lib/rspec/junklet/junk_spec.rb
|
107
120
|
- spec/lib/rspec/junklet/junklet_spec.rb
|
108
121
|
- spec/spec_helper.rb
|
122
|
+
- spec/support/banner.rb
|
109
123
|
homepage: https://github.com/dbrady/rspec-junklet
|
110
124
|
licenses:
|
111
125
|
- MIT
|
@@ -116,17 +130,17 @@ require_paths:
|
|
116
130
|
- lib
|
117
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
132
|
requirements:
|
119
|
-
- -
|
133
|
+
- - ">="
|
120
134
|
- !ruby/object:Gem::Version
|
121
135
|
version: '0'
|
122
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
137
|
requirements:
|
124
|
-
- -
|
138
|
+
- - ">="
|
125
139
|
- !ruby/object:Gem::Version
|
126
140
|
version: '0'
|
127
141
|
requirements: []
|
128
142
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.5.1
|
130
144
|
signing_key:
|
131
145
|
specification_version: 4
|
132
146
|
summary: Easily create junk data for specs
|
@@ -145,3 +159,4 @@ test_files:
|
|
145
159
|
- spec/lib/rspec/junklet/junk_spec.rb
|
146
160
|
- spec/lib/rspec/junklet/junklet_spec.rb
|
147
161
|
- spec/spec_helper.rb
|
162
|
+
- spec/support/banner.rb
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-1.9.3-p551
|