rspec-junklet 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTBkNmE5YzhiNjBkZTE5MTE4OWM5YzAxMzI1NzIwMmUxMjEzNTljOA==
4
+ Y2JjYzc5MDljNGNlMjQwNWI0ZjA3YjM3NWM0NTQwYTVmZjc2ZWFkYg==
5
5
  data.tar.gz: !binary |-
6
- ZWIxZjZkNTg2NmVhMmVlYjYzYTdkMWJhMDdhYTc4YTIwZmY5MzhkNg==
6
+ ODRiNWRkZjg5MDNmOTlhMGVkYmE4MzA5ZDdjMWNkMWQyOTc4ZDc3MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmEzM2E4OWJiMWUyOGY4MDM0YWNjN2ZhODlhN2ZkOWM4NjEyOThhMjFkMjM3
10
- MmYyOWVkMzU4ZDc2ODIzYTZhYzVmZTdhZTM3YjkyNzE0MmRkNjhmYzAxOTBh
11
- OTg1ZjI0ZTk5ODE4NWRmOTA1ZmY1NDA3ODE1Zjg5ZDc2YWEyNWU=
9
+ ZDNiODg5ZDhiYTFmMTc0M2VjNWU4MGVhZjgyNjJmYzQxN2NjNjk5MzllNWFj
10
+ ZTQ3NTkxMzAzNTZlOGE2MDhkMWEyYjVmYTI3Y2I1ZmY3MmFiOTlkYTM2NzFj
11
+ MmVhNzhlZGUzOTM4ZTI3Yzc4NjE3NDAwYTBhODg3MjVjZmU4YWY=
12
12
  data.tar.gz: !binary |-
13
- YjVhMjU5ODEwNzYzZTg3MTk5YzZhODA4MWU1NTA3NjY5NjRmMGM0ZDdjMjc5
14
- NzhiMzJjYjgwYTEyMTcxNzlhYTEyMTA4ODRlOTg0YWE5MWZhOTVlZDBjYWE2
15
- OTg3MzdkMmUxZGY2OGE0NjEwZGNlYjg0Y2Y1YWE0ZTllMTBlZmU=
13
+ YWUzYTRjZTkxMWRjYTVkYTI1ZmYxODZjY2NiOTBhOGUwZDQwMjFlMzA2ZDI0
14
+ ZDdiZGZmZGE5OThhZjgwNWY4ZjFlNDhkMDkzODFhMWI0NmEzN2Y3NDEyMWIw
15
+ Mjk4ZTBlMmM4YjQ2MDY3ZDRiYzZjM2I1ZGJlMTA4MmJhMDc1ZmE=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-junklet (2.0.0)
4
+ rspec-junklet (2.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -42,13 +42,16 @@ and varied types of junk data. The former is meant to be used as part of the DSL
42
42
  to declare pieces of data to be junk, while the latter is intended to be used
43
43
  anywhere inside RSpec to supply the junk data itself.
44
44
 
45
- To illustrate, these statements are functionally identical:
45
+ To illustrate, these statements are essentially identical:
46
46
 
47
47
  ```ruby
48
48
  junklet :pigtruck
49
49
  let(:pigtruck) { junk }
50
50
  ```
51
51
 
52
+ _Caveat: they are slightly different; `junklet :pigtruck` is actually identical
53
+ to `let(:pigtruck) { "pigtruck-" + junk }`_
54
+
52
55
  ## Junklet
53
56
 
54
57
  `junklet` declares a memoized variable containing random junk.
@@ -15,12 +15,12 @@ module RSpec
15
15
  names = names.map {|name| name.gsub(/_/, separator)}
16
16
 
17
17
  args.zip(names).each do |arg, name|
18
- make_junklet arg, name, separator, junk
18
+ make_junklet arg, name, separator
19
19
  end
20
20
  end
21
21
 
22
- def make_junklet(let_name, name, separator, junk_data)
23
- let(let_name) { "#{name}#{separator}#{junk_data}" }
22
+ def make_junklet(let_name, name, separator)
23
+ let(let_name) { "#{name}#{separator}#{junk}" }
24
24
  end
25
25
  end
26
26
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Junklet
3
- VERSION = "2.1.0"
3
+ VERSION = "2.1.1"
4
4
  end
5
5
  end
@@ -15,8 +15,8 @@ describe RSpec::Junklet do
15
15
  specify { expect(trash).to match /^trash_/ }
16
16
  specify { expect(trash).to match hex_regex }
17
17
 
18
- describe "memoization" do
19
- specify { expect(trash).to eq(trash) }
18
+ it "memoizes so subsequent calls do not change" do
19
+ expect(trash).to eq(trash)
20
20
  end
21
21
  end
22
22
 
@@ -168,16 +168,6 @@ describe RSpec::Junklet do
168
168
  end
169
169
  end
170
170
 
171
- # begin
172
- # $caught_bad_junklet_error = false
173
- # junklet :cheesy_bad_junklet, cheese: true
174
- # rescue INVALID_JUNKLET_ERROR => e
175
- # raise "junklet got invalid option" unless e.message == "junklet options must be one of #{VALID_JUNKLET_ARGS.map(&:inspect) * ', '}"
176
- # $caught_bad_junklet_error = true
177
- # else
178
- # raise "junklet got an invalid argument but didn't catch it" unless $caught_bad_junklet_error
179
- # end
180
-
181
171
  context "with exclude: val" do
182
172
  let(:heads) { 0 }
183
173
  let(:tails) { 1 }
@@ -188,12 +178,45 @@ describe RSpec::Junklet do
188
178
  specify { expect(coin_tails).to eq(tails) }
189
179
  end
190
180
 
181
+ context "with format" do
182
+ context "format: :string" do
183
+ let(:age_string) { junk :int, size: 2, format: :string }
184
+ it "changes junk to a string" do
185
+ expect(age_string).to match /^\d\d$/
186
+ end
187
+ end
188
+
189
+ context "format: <string>" do
190
+ let(:birthday) { junk :int, max: 9, format: "03/15/20%02d" }
191
+ it "formats using the string as a sprintf format" do
192
+ expect(birthday).to match %r{^03/15/200\d$}
193
+ end
194
+ end
195
+
196
+ context "format: SomeClass" do
197
+ class Birthday
198
+ def initialize(day)
199
+ @day = day
200
+ end
201
+ def format
202
+ "%02d/%02d/20%02d" % [@day, @day, @day]
203
+ end
204
+ end
205
+
206
+ let(:birthday) { junk :int, max: 12, format: Birthday }
207
+ it "uses the class as a formatter instance with .new(junk).format" do
208
+ expect(birthday).to match %r{^\d\d/\d\d/20\d\d$}
209
+ end
210
+ end
211
+ end
212
+
191
213
  # TODO: Formats here
192
214
 
193
215
  # format: :string -> calls .to_s
194
216
  # format: "format_string" -> calls sprintf(junkval, format_string)
195
217
  # format: Klass -> passes junkval to Klass.new
196
218
  # format: Proc -> passes junkval to Proc
219
+ # format: :sym -> calls .to_sym
197
220
  #
198
221
  # format: with exclude: - runs exclude AFTER running format. This is the whole point of formatters; it allows us to say junk().to_s, exclude: :otherval
199
222
 
@@ -205,4 +228,24 @@ describe RSpec::Junklet do
205
228
  specify { expect(metaname).to be }
206
229
  end
207
230
  end
231
+
232
+
233
+ # describe '.junks' do
234
+ # junks :age, :size, :weight, type: :int, format: :string
235
+
236
+ # it "makes all the defined junk objects the same type" do
237
+ # expect(age).to be_a String
238
+ # expect(size).to be_a String
239
+ # expect(weight).to be_a String
240
+ # end
241
+
242
+ # it "formats all the junk objects per the formatter" do
243
+ # # This is why it's not just an extra param to junklet: junklet
244
+ # # prepends the name of the symbol.
245
+ # expect(age).to match /^\d+$/
246
+ # expect(size).to match /^\d+$/
247
+ # expect(weight).to match /^\d+$/
248
+ # end
249
+ # end
250
+
208
251
  end
@@ -25,15 +25,15 @@ describe JunkletSpy do
25
25
  end
26
26
 
27
27
  it 'delegates junk generation to junk' do
28
- expect(subject).to receive(:make_junklet).with(:pig_truck, 'pig_truck', '_', 'junkety_junky_junk')
29
- expect(subject).to receive(:make_junklet).with(:cow_truck, 'cow_truck', '_', 'junkety_junky_junk')
28
+ expect(subject).to receive(:make_junklet).with(:pig_truck, 'pig_truck', '_')
29
+ expect(subject).to receive(:make_junklet).with(:cow_truck, 'cow_truck', '_')
30
30
  subject.junklet :pig_truck, :cow_truck
31
31
  end
32
32
 
33
33
  context "with separator" do
34
34
  it 'converts separator in name' do
35
- expect(subject).to receive(:make_junklet).with(:pig_truck, 'pig~truck', '~', 'junkety_junky_junk')
36
- expect(subject).to receive(:make_junklet).with(:cow_truck, 'cow~truck', '~', 'junkety_junky_junk')
35
+ expect(subject).to receive(:make_junklet).with(:pig_truck, 'pig~truck', '~')
36
+ expect(subject).to receive(:make_junklet).with(:cow_truck, 'cow~truck', '~')
37
37
  subject.junklet :pig_truck, :cow_truck, separator: '~'
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-junklet
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.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: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler