junklet 0.9.2 → 1.0.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDdlODdiZDE4MzI3Njk2YjBiZmQ0NTQ1ZDEwMzc3NmY0YTdkNGE3Mw==
4
+ YTc3MWM0MDE5OTgyMDZhNjJiMzU1YmY3NzY2MWYwMDA3N2ZlYzU0Yg==
5
5
  data.tar.gz: !binary |-
6
- OWRhN2UxYTQxNzk0MGI1NGNiYjRlZGQ0YTVlMzE2ODAzZGYzZjhjNg==
6
+ YzZkMTI1ZDMwZjE3ZDg0ODI1MDcxOTEwZTQ3MmY0MDY5MTc5NTdjNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTJjYzEzNDIxNmQwMzkwNzg0N2U4MTQyMTUxMTgzYjNiNjFhYzJlNmIyMTg3
10
- ZmZjOTQxOTIzOTFlZjFhZDcwMDViYTM5NDU0YmUyODA5YjUwOTljYTQ3MWRl
11
- M2I4ODk5YWRmMjk4NTRlMTNjYjQxZGUyZWQyZDBlODYwZTYzZTM=
9
+ YmNkODBhODcyN2M2Y2U0NWZmMmJlNzMxOWZlNmQ5OTBkNTA5OWEzMjNlNzMw
10
+ YmQwMWQ5MmM4NDVhOWVkYWIzY2ZjNTQ2NDM4YjdjOWZmYWY5YzU5YWUwY2Qw
11
+ ZGUxYzczMmI5ODFlYTdmODJkNjc4Y2MzZTE5YTVhNzMyZTFkZmE=
12
12
  data.tar.gz: !binary |-
13
- ZWJmMWNlNGQ4MGU1YzY3ZTIwZGE1M2YxY2YzODgyZTgwZjU0YjdkY2EzNGNm
14
- MGUwODZhYWNjMDNiMjRmMzM1NDI4MDk5MjQ3NDFiYjlkYzhjNWNlZWUzNjUw
15
- NDQyZjEwYzU1N2I1ZmQxMTY2ZTY2N2QxZWIxMTllMmM2MjczYTg=
13
+ NGI0MmYyNDA0MTJmOTJlY2ExYzAxY2Q5MDdjNTEwNTY3Zjc3YjJiOTFlMTli
14
+ NjIyNDVkZDkzYjZmMzY2Njg3MzEyZDZhOGRmNTdkMzg2N2M4NDk2YWE3YTBh
15
+ MWU5MmIxODYxOTRhZDdjOWEyNWQwNTc1ZGVmMmM1MWY1ZjcwYzg=
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p551
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- junklet (0.9.1)
4
+ junklet (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  builder (3.2.2)
10
+ coderay (1.1.0)
10
11
  cucumber (1.3.18)
11
12
  builder (>= 2.1.2)
12
13
  diff-lcs (>= 1.1.3)
@@ -16,8 +17,13 @@ GEM
16
17
  diff-lcs (1.2.5)
17
18
  gherkin (2.12.2)
18
19
  multi_json (~> 1.3)
20
+ method_source (0.8.2)
19
21
  multi_json (1.10.1)
20
22
  multi_test (0.1.1)
23
+ pry (0.10.1)
24
+ coderay (~> 1.1.0)
25
+ method_source (~> 0.8.1)
26
+ slop (~> 3.4)
21
27
  rake (10.4.2)
22
28
  rspec (2.99.0)
23
29
  rspec-core (~> 2.99.0)
@@ -27,6 +33,7 @@ GEM
27
33
  rspec-expectations (2.99.2)
28
34
  diff-lcs (>= 1.1.3, < 2.0)
29
35
  rspec-mocks (2.99.2)
36
+ slop (3.6.0)
30
37
 
31
38
  PLATFORMS
32
39
  ruby
@@ -35,5 +42,6 @@ DEPENDENCIES
35
42
  bundler (~> 1.7)
36
43
  cucumber
37
44
  junklet!
45
+ pry
38
46
  rake (~> 10.0)
39
47
  rspec (~> 2.0)
data/junklet.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 2.0"
24
24
  spec.add_development_dependency "cucumber"
25
+ spec.add_development_dependency "pry"
25
26
  end
@@ -1,3 +1,3 @@
1
1
  module Junklet
2
- VERSION = "0.9.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/junklet.rb CHANGED
@@ -20,16 +20,13 @@ module RSpec
20
20
  end
21
21
 
22
22
  def junk(size=32)
23
- trash = ""
24
- trash += SecureRandom.hex while trash.size < size
25
- trash = trash[0...size]
23
+ # hex returns size*2 digits, because it returns a 0..255 byte
24
+ # as a hex pair. But when we want junt, we want *bytes* of
25
+ # junk. Get (size+1)/2 chars, which will be correct for even
26
+ # sizes and 1 char too many for odds, so trim off with
27
+ # [0...size] (note three .'s to trim off final char)
28
+ SecureRandom.hex((size+1)/2)[0...size]
26
29
  end
27
30
  end
28
-
29
- # class ExampleGroup
30
- # def self.junk
31
- # SecureRandom.hex
32
- # end
33
- # end
34
31
  end
35
32
  end
@@ -0,0 +1,151 @@
1
+ # What it does:
2
+ # Find blocks of mixed lets and "junklets", a special DSL term we use here for
3
+ # junk data. It then rewrites the block so that the lets come first in
4
+ # original order, then a newline, then the junklets in order. So it turns this
5
+ # code:
6
+ #
7
+ # let(:name) { "Bob" }
8
+ # junklet :address
9
+ # let(:city) { "Faketown" }
10
+ # junklet :state
11
+ # junklet :zip
12
+ # let(:extra) { true }
13
+ # let(:pants) { ON_FIRE }
14
+ #
15
+ # Into THIS code, leaving the rest of the file unaltered:
16
+ #
17
+ # let(:name) { "Bob" }
18
+ # let(:city) { "Faketown" }
19
+ # let(:extra) { true }
20
+ # let(:pants) { ON_FIRE }
21
+ #
22
+ # junklet :address
23
+ # junklet :state
24
+ # junklet :zip
25
+ #
26
+
27
+ require_relative 'line'
28
+
29
+ # As with all parsers, this is easy if we allow peeking.
30
+ class JunkletUpgradeParser
31
+ attr_reader :lines, :lets, :junklets, :mode, :current_line
32
+
33
+ INACTIVE = 'inactive'
34
+ MAYBE_ACTIVE = 'maybe_active'
35
+ ACTIVE = 'active'
36
+
37
+ def initialize
38
+ end
39
+
40
+ def inactive; INACTIVE; end
41
+ def maybe_active; MAYBE_ACTIVE; end
42
+ def active; ACTIVE; end
43
+
44
+ def inactive?; mode == inactive; end
45
+ def maybe_active?; mode == maybe_active; end
46
+ def active?; mode == active; end
47
+
48
+ def upgraded_lines(lines)
49
+ @lines = lines
50
+ return unless junky?
51
+ we_are_inactive!
52
+ emitted_lines = []
53
+ lines.each do |line|
54
+ self.current_line = imblart_line(line)
55
+ case mode
56
+ when inactive
57
+ if current_line.let?
58
+ lets << parse_line(current_line)
59
+ we_are_maybe_active!
60
+ elsif current_line.junklet?
61
+ junklets << current_line
62
+ we_are_active!
63
+ elsif current_line.code?
64
+ emitted_lines << parse_line(current_line)
65
+ end
66
+ when maybe_active
67
+ if current_line.let?
68
+ lets << parse_line(current_line)
69
+ elsif current_line.junklet?
70
+ junklets << current_line
71
+ we_are_active!
72
+ elsif current_line.code?
73
+ emitted_lines += lets
74
+ emitted_lines << parse_line(current_line)
75
+ we_are_inactive!
76
+ end
77
+ when active
78
+ if current_line.let?
79
+ lets << parse_line(current_line)
80
+ elsif current_line.junklet?
81
+ junklets << current_line
82
+ elsif current_line.code?
83
+ emitted_lines += reordered_block
84
+ emitted_lines << parse_line(current_line)
85
+ reset
86
+ we_are_inactive!
87
+ end
88
+ end
89
+ end
90
+
91
+ # if lets || junklets we've hit EOF while active
92
+ emitted_lines += reordered_block if active?
93
+ emitted_lines
94
+ end
95
+
96
+ def parse_line(line)
97
+ numeric_range_match = /(\s*)SecureRandom.(hex|uuid)\[(\d+)\.\.(\d+)\](\s*)/
98
+ range_match = /(\s*)SecureRandom.(hex|uuid)\[(\d+)\.\.(.+?)\](\s*)/
99
+ simple_match = /(\s*)SecureRandom.(hex|uuid)(\s*)/
100
+
101
+ # match these in order--simple match will match all complicated matches.
102
+ line \
103
+ .gsub(numeric_range_match) {|s| "#{$1}junk(#{$4.to_i-$3.to_i})#{$5}" } \
104
+ .gsub(range_match) {|s| "#{$1}junk(#{$4})#{$5}" } \
105
+ .gsub(simple_match) {|s| "#{$1}junk#{$3}" }
106
+ end
107
+
108
+ def reordered_block
109
+ lets << "\n" unless lets.empty? || lets.last == "\n" || junklets.empty?
110
+ lets + sort_junklets
111
+ end
112
+
113
+ def sort_junklets
114
+ return if junklets.empty?
115
+ indent = junklets.first.indent
116
+ ["#{indent}junklet #{(junklets.map(&:names).sort * ', ')}\n"]
117
+ end
118
+
119
+ def imblart_line(line)
120
+ Line.new line
121
+ end
122
+
123
+ def we_are_inactive!
124
+ reset
125
+ @mode = INACTIVE
126
+ end
127
+
128
+ def we_are_maybe_active!
129
+ @mode = MAYBE_ACTIVE
130
+ end
131
+
132
+ def we_are_active!
133
+ @mode = ACTIVE
134
+ end
135
+
136
+ def reset
137
+ @lets, @junklets = [], []
138
+ end
139
+
140
+ def junky?
141
+ lines.any? { |line| junk_line? line }
142
+ end
143
+
144
+ def junk_line?(line)
145
+ line =~ /\bSecureRandom\./ || line =~ /\bjunklet\b/
146
+ end
147
+
148
+ private
149
+
150
+ attr_accessor :current_line
151
+ end
data/lib/line.rb ADDED
@@ -0,0 +1,44 @@
1
+ class Line < String
2
+ def initialize(line="")
3
+ super
4
+ end
5
+
6
+ def indent
7
+ ' ' * (size - lstrip.size)
8
+ end
9
+
10
+ def let?
11
+ match(/^\s*let\s*\(/) && !junklet?
12
+ end
13
+
14
+ def junklet?
15
+ already_junklet? || secure_random?
16
+ end
17
+
18
+ def already_junklet?
19
+ match(/^\s*junklet\b/)
20
+ end
21
+
22
+ def secure_random?
23
+ match(/^\s*(let)\s*\(?([^)]*)\)\s*{\s*SecureRandom.(uuid|hex)\s*}/)
24
+ end
25
+
26
+ def code?
27
+ empty? || (!let? && !junklet?)
28
+ end
29
+
30
+ def names
31
+ return nil unless let? || junklet?
32
+ match(/^\s*(let|junklet)\s*\(?([^)]*)\)?/) \
33
+ .captures[1..-1] \
34
+ .join('') \
35
+ .split(/,/) \
36
+ .map(&:strip)
37
+ end
38
+
39
+ def convert
40
+ return nil unless junklet?
41
+ return self if already_junklet?
42
+ Line.new("#{indent}junklet #{names.first}")
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ let(:name) { "Bob" }
2
+ let(:city) { "Faketown" }
3
+ let(:extra) { true }
4
+ let(:pants) { ON_FIRE }
5
+
6
+ junklet :address, :state, :zip
@@ -0,0 +1,7 @@
1
+ let(:name) { "Bob" }
2
+ junklet :address
3
+ let(:city) { "Faketown" }
4
+ junklet :state
5
+ junklet :zip
6
+ let(:extra) { true }
7
+ let(:pants) { ON_FIRE }
@@ -0,0 +1,6 @@
1
+ describe SomeClass do
2
+ let(:key) { junk.to_sym }
3
+ let(:xml_node) { { key => value } }
4
+
5
+ junklet :a_value, :new_value, :other_value, :value
6
+ end
@@ -0,0 +1,9 @@
1
+ describe SomeClass do
2
+ let(:key) { junk.to_sym }
3
+ let(:xml_node) { { key => value } }
4
+
5
+ junklet :value
6
+ junklet :other_value
7
+ junklet :new_value
8
+ junklet :a_value
9
+ end
@@ -0,0 +1,8 @@
1
+ let(:first_name) { "TestBot" }
2
+ let(:last_name) { "ID-#{junk(8)}" }
3
+ let(:city) { junk(MAX_CITY_NAME_LENGTH-1) }
4
+ let(:extra) { junk(4) }
5
+ let(:pants) { junk(64) }
6
+ let(:other_pants) { junk(66) }
7
+
8
+ junklet :address, :state, :zip
@@ -0,0 +1,9 @@
1
+ let(:first_name) { "TestBot" }
2
+ let(:last_name) { "ID-#{SecureRandom.hex[0..8]}" }
3
+ let(:address) { SecureRandom.uuid }
4
+ let(:city) { SecureRandom.uuid[0..MAX_CITY_NAME_LENGTH-1] }
5
+ let(:state) { SecureRandom.uuid }
6
+ let(:zip) {SecureRandom.uuid}
7
+ let(:extra) { "www.#{SecureRandom.uuid[6..10].com" }
8
+ let(:pants) { SecureRandom.hex 32 }
9
+ let(:other_pants) { SecureRandom.hex(33) }
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe XMLCommon do
4
+ subject do
5
+ node = xml_node
6
+ Class.new do
7
+ include XMLCommon
8
+ define_method(:xml_node) { node }
9
+ end.new
10
+ end
11
+
12
+ describe "#fetch" do
13
+ it "looks in the `:from` element" do
14
+ other_key, other_value = Array.new(2) { junk }
15
+ from = { other_key.to_sym => other_value }
16
+ expect(subject.fetch(other_key, from: from)).to \
17
+ eq(other_value)
18
+ end
19
+
20
+ it "fails if the attribute isn't in `:from`" do
21
+ missing_key = junk.to_sym
22
+ expect{ subject.fetch(missing_key) }.to \
23
+ raise_error(XMLCommon::AttributeNotFound)
24
+ end
25
+
26
+ it "defaults to `xml_node`" do
27
+ expect(subject.fetch(key)).to eq(value)
28
+ end
29
+ end
30
+
31
+ specify "xml_node" do
32
+ pending "i wouldn't usually test this, but since it's going to be inherited, i think it's a good idea"
33
+ end
34
+
35
+ specify "#==" do
36
+ pending
37
+ end
38
+
39
+ specify "#to_s" do
40
+ pending
41
+ end
42
+
43
+ let(:key) { junk.to_sym }
44
+ let(:xml_node) { { key => value } }
45
+
46
+ junklet :value
47
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ describe XMLCommon do
4
+ subject do
5
+ node = xml_node
6
+ Class.new do
7
+ include XMLCommon
8
+ define_method(:xml_node) { node }
9
+ end.new
10
+ end
11
+
12
+ describe "#fetch" do
13
+ it "looks in the `:from` element" do
14
+ other_key, other_value = Array.new(2) { junk }
15
+ from = { other_key.to_sym => other_value }
16
+ expect(subject.fetch(other_key, from: from)).to \
17
+ eq(other_value)
18
+ end
19
+
20
+ it "fails if the attribute isn't in `:from`" do
21
+ missing_key = junk.to_sym
22
+ expect{ subject.fetch(missing_key) }.to \
23
+ raise_error(XMLCommon::AttributeNotFound)
24
+ end
25
+
26
+ it "defaults to `xml_node`" do
27
+ expect(subject.fetch(key)).to eq(value)
28
+ end
29
+ end
30
+
31
+ specify "xml_node" do
32
+ pending "i wouldn't usually test this, but since it's going to be inherited, i think it's a good idea"
33
+ end
34
+
35
+ specify "#==" do
36
+ pending
37
+ end
38
+
39
+ specify "#to_s" do
40
+ pending
41
+ end
42
+
43
+ let(:key) { junk.to_sym }
44
+ junklet :value
45
+ let(:xml_node) { { key => value } }
46
+ end
@@ -0,0 +1,6 @@
1
+ let(:name) { "Bob" }
2
+ let(:city) { "Faketown" }
3
+ let(:extra) { true }
4
+ let(:pants) { ON_FIRE }
5
+
6
+ junklet :address, :state, :zip
@@ -0,0 +1,7 @@
1
+ let(:name) { "Bob" }
2
+ let(:address) { SecureRandom.uuid }
3
+ let(:city) { "Faketown" }
4
+ let(:state) { SecureRandom.uuid }
5
+ let(:zip) {SecureRandom.uuid}
6
+ let(:extra) { true }
7
+ let(:pants) { ON_FIRE }
@@ -46,7 +46,8 @@ describe Junklet do
46
46
  let(:trash) { junk }
47
47
 
48
48
  specify { expect(trash).to match hex_regex }
49
-
49
+ specify { expect(trash.size).to eq(32) }
50
+
50
51
  it "is not cached" do
51
52
  expect(junk).to_not eq(junk)
52
53
  end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+ require_relative '../../lib/junklet_upgrade_parser'
3
+
4
+
5
+ describe JunkletUpgradeParser do
6
+ specify { expect(JunkletUpgradeParser).to be }
7
+
8
+ let(:parser) { JunkletUpgradeParser.new }
9
+
10
+ # Process test files
11
+ context "with test fixtures" do
12
+ # TODO: Mothballing upgrader for now. Embedded gives a good
13
+ # example of how the parser is fascinatingly broken.
14
+ #%w(block1 mixed_code combined old_skool embedded).each do |name|
15
+ %w(block1 mixed_code combined old_skool).each do |name|
16
+ describe "processing #{name}_before.txt -> #{name}_after.txt" do
17
+ let(:fixture_path) { File.expand_path(File.join(File.dirname(__FILE__), '../fixtures')) }
18
+ let(:lines) { IO.readlines("#{fixture_path}/#{name}_before.txt") }
19
+ let(:output_file) { "#{fixture_path}/#{name}_after.txt" }
20
+ let(:output_lines) { IO.readlines(output_file) }
21
+
22
+ specify { expect(parser.upgraded_lines(lines)).to eq(output_lines) }
23
+ specify { expect(parser.upgraded_lines(lines) * '').to eq(File.read(output_file)) }
24
+
25
+ # This dumps a purty colorized diff of what we expected to get
26
+ # on the left against what we actually got on the right. It's
27
+ # a very helpful visual aid when the spec is acting up. It's a
28
+ # fork in the eyeballs* if you just want to see green dots.
29
+ #
30
+ # * two forks, if you're into async
31
+ # it "dumps the file diff (no-op spec)" do
32
+ # parsed_lines = parser.upgraded_lines(lines)
33
+
34
+ # puts '-' * 80
35
+ # dump_diff(output_lines, parser.upgraded_lines(lines))
36
+ # puts '-' * 80
37
+ # puts parser.inspect
38
+ # end
39
+ end
40
+ end
41
+ end
42
+
43
+ # TODO: replace this with a hash of line => replacement pairs and a single spec
44
+ describe '#parse_line' do
45
+ context 'when line contains no SecureRandom.uuid or SecureRandom.hex calls' do
46
+ let(:line) { SecureRandom.hex(100) }
47
+ specify { expect(subject.parse_line(line)).to eq(line) }
48
+ end
49
+
50
+ # context "when line contains SecureRandom.hex(int)" do
51
+ # let(:line) { ' emit_noise("#{SecureRandom.hex(12)")' }
52
+ # it { pending "write me you clods" }
53
+ # end
54
+
55
+ # context "when line contains SecureRandom.hex int" do
56
+ # it { pending "write me you clods" }
57
+ # end
58
+
59
+ [:hex, :uuid].each do |method|
60
+ context "when line contains SecureRandom.#{method}" do
61
+ let(:line) { " let(:extra_fields) { Array.new(2) { SecureRandom.#{method} } }" }
62
+ it "replaces SecureRandom.#{method} with junk" do
63
+ expect(parser.parse_line(line)).to eq(' let(:extra_fields) { Array.new(2) { junk } }')
64
+ end
65
+ end
66
+
67
+ context "when extra whitespace is present around SecureRandom.#{method}" do
68
+ let(:line) { " let(:extra_fields) { Array.new(2) { SecureRandom.#{method} } }" }
69
+ it "replaces SecureRandom.#{method} with junk" do
70
+ expect(parser.parse_line(line)).to eq(' let(:extra_fields) { Array.new(2) { junk } }')
71
+ end
72
+ end
73
+
74
+ context "when line contains SecureRandom.#{method}[range]" do
75
+ context "and range is [int..int] (e.g. [0..10])" do
76
+ let(:line) { "question_id: SecureRandom.#{method}[0..10]" }
77
+ it "replaces SecureRandom.#{method}[0..10] with junk(10)" do
78
+ expect(parser.parse_line(line)).to eq('question_id: junk(10)')
79
+ end
80
+ end
81
+
82
+ context "and range is of form [n..int]" do
83
+ let(:line) { "question_id: SecureRandom.#{method}[3..10]" }
84
+ it "replaces SecureRandom.#{method}[0..10] with junk(7)" do
85
+ expect(parser.parse_line(line)).to eq('question_id: junk(7)')
86
+ end
87
+ end
88
+
89
+ context "and range is [0..var] (e.g. [0..MAX_QUESTION_ID_LEN-1]" do
90
+ let(:line) { "SecureRandom.#{method}[0..Mogrifier::NcpdpScriptStandard::MAX_QUESTION_ID_LEN-1]" }
91
+ it "replaces SecureRandom.#{method}[0..n] with junk(n)" do
92
+ expect(parser.parse_line(line)).to eq('junk(Mogrifier::NcpdpScriptStandard::MAX_QUESTION_ID_LEN-1)')
93
+ end
94
+ end
95
+ # TODO: three-dot ranges not yet supported due to rarity.
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+ require_relative '../../lib/line'
3
+
4
+ describe Line do
5
+ let(:code) { Line.new(" # Here's some code\n") }
6
+ let(:let) { Line.new(" let(:bob) { 'Bob McRobertson' } \n") }
7
+ let(:uuid) { Line.new(" let(:uuid) { SecureRandom.uuid }\n") }
8
+ let(:hex) { Line.new(" let(:hex) { SecureRandom.hex }\n") }
9
+ let(:junklet) { Line.new(" junklet :reggie\n") }
10
+ let(:multi) { Line.new(" junklet :john, :paul, :ringo, :the_other_one") }
11
+ let(:blank) { Line.new("\n") }
12
+ let(:embedded) { Line.new(' let(:embedded) { "www.#{SecureRandom.uuid}.com" }\n') }
13
+
14
+ let(:uuid_arg) { Line.new(' let(:uuid_arg) { SecureRandom.uuid[0..10] }') }
15
+ let(:hex_arg) { Line.new(' let(:hex_arg) { SecureRandom.hex[0..10] }') }
16
+
17
+ specify { code.should be_code }
18
+ specify { code.should_not be_let }
19
+ specify { code.should_not be_junklet }
20
+ specify { code.names.should be_nil }
21
+ specify { code.convert.should be_nil }
22
+
23
+ specify { let.should_not be_code }
24
+ specify { let.should be_let }
25
+ specify { let.should_not be_junklet }
26
+ specify { let.names.should eq([':bob']) }
27
+ specify { let.convert.should be_nil }
28
+
29
+ specify { uuid.should_not be_code }
30
+ specify { uuid.should_not be_let }
31
+ specify { uuid.should be_junklet }
32
+ specify { uuid.convert.should eq(Line.new(" junklet :uuid")) }
33
+
34
+ specify { junklet.should_not be_code }
35
+ specify { junklet.should_not be_let }
36
+ specify { junklet.should be_junklet }
37
+ specify { junklet.names.should eq([':reggie']) }
38
+ specify { junklet.convert.should eq(junklet) }
39
+
40
+ specify { multi.should_not be_code }
41
+ specify { multi.should_not be_let }
42
+ specify { multi.should be_junklet }
43
+ specify { multi.names.should eq([':john', ':paul', ':ringo', ':the_other_one']) }
44
+ specify { multi.convert.should eq(multi) }
45
+
46
+ specify { blank.should be_code }
47
+ specify { blank.should_not be_let }
48
+ specify { blank.should_not be_junklet }
49
+ specify { blank.names.should be_nil }
50
+ specify { blank.convert.should be_nil }
51
+
52
+ specify { embedded.should_not be_code }
53
+ specify { embedded.should be_let }
54
+ specify { embedded.should_not be_junklet }
55
+ specify { embedded.names.should eq([':embedded']) }
56
+ specify { embedded.convert.should be_nil }
57
+
58
+ specify { hex.should_not be_code }
59
+ specify { hex.should_not be_let }
60
+ specify { hex.should be_junklet }
61
+ specify { hex.names.should eq([':hex']) }
62
+ specify { hex.convert.should eq(" junklet :hex") }
63
+
64
+ specify { uuid_arg.should_not be_code }
65
+ specify { uuid_arg.should be_let }
66
+ specify { uuid_arg.should_not be_junklet }
67
+ specify { uuid_arg.names.should eq([':uuid_arg']) }
68
+ specify { uuid_arg.convert.should be_nil }
69
+
70
+ specify { hex_arg.should_not be_code }
71
+ specify { hex_arg.should be_let }
72
+ specify { hex_arg.should_not be_junklet }
73
+ specify { hex_arg.names.should eq([':hex_arg']) }
74
+ specify { hex_arg.convert.should be_nil }
75
+
76
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,45 @@
1
1
  # spec_helper.rb
2
2
 
3
3
  require_relative '../lib/junklet'
4
+
5
+ require 'pry'
6
+
7
+ # Since we've kept rigidly to 80-columns, we can easily
8
+ # Do a pretty side-by-side diff here. This won't handle
9
+ # Line deletions/insertions but for same/same diffs it'll
10
+ # work fine.
11
+ ESC = 27.chr
12
+ GREEN = "%c[%sm" % [ESC, 32]
13
+ RED = "%c[%sm" % [ESC, 31]
14
+ RESET = "%c[0m" % ESC
15
+
16
+ def dump_hline
17
+ puts(('-' * 80) + '-+-' + ('-' * 80))
18
+ end
19
+
20
+ def dump_captions
21
+ puts '%-80s | %s' % ["EXPECTED", "GOT"]
22
+ end
23
+
24
+ def dump_header
25
+ dump_hline
26
+ dump_captions
27
+ end
28
+
29
+ def dump_footer
30
+ dump_hline
31
+ end
32
+
33
+ def line_pairs(expected_lines, got_lines)
34
+ expected_lines.zip(got_lines).map { |words| words.map {|w| w ? w.rstrip : '' } }
35
+ end
36
+
37
+ def dump_diff(expected_lines, got_lines)
38
+ dump_header
39
+
40
+ line_pairs(expected_lines, got_lines).each do |a,b|
41
+ color_code = a == b ? GREEN : RED
42
+ puts "#{color_code}%-80s | %s#{RESET}" % [a,b]
43
+ end
44
+ dump_footer
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junklet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Brady
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Works like let for rspec, but creates unique random junk data
70
84
  email:
71
85
  - dbrady@covermymeds.com
@@ -75,15 +89,29 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - .gitignore
77
91
  - .rspec
92
+ - .ruby-version
78
93
  - Gemfile
79
94
  - Gemfile.lock
80
95
  - LICENSE
81
96
  - README.md
82
- - Rakefile
83
97
  - junklet.gemspec
84
98
  - lib/junklet.rb
85
99
  - lib/junklet/version.rb
100
+ - lib/junklet_upgrade_parser.rb
101
+ - lib/line.rb
102
+ - spec/fixtures/block1_after.txt
103
+ - spec/fixtures/block1_before.txt
104
+ - spec/fixtures/combined_after.txt
105
+ - spec/fixtures/combined_before.txt
106
+ - spec/fixtures/embedded_after.txt
107
+ - spec/fixtures/embedded_before.txt
108
+ - spec/fixtures/mixed_code_after.txt
109
+ - spec/fixtures/mixed_code_before.txt
110
+ - spec/fixtures/old_skool_after.txt
111
+ - spec/fixtures/old_skool_before.txt
86
112
  - spec/lib/junklet_spec.rb
113
+ - spec/lib/junklet_upgrade_parser_spec.rb
114
+ - spec/lib/line_spec.rb
87
115
  - spec/spec_helper.rb
88
116
  homepage: ''
89
117
  licenses:
@@ -110,5 +138,17 @@ signing_key:
110
138
  specification_version: 4
111
139
  summary: Easily create junk data for specs
112
140
  test_files:
141
+ - spec/fixtures/block1_after.txt
142
+ - spec/fixtures/block1_before.txt
143
+ - spec/fixtures/combined_after.txt
144
+ - spec/fixtures/combined_before.txt
145
+ - spec/fixtures/embedded_after.txt
146
+ - spec/fixtures/embedded_before.txt
147
+ - spec/fixtures/mixed_code_after.txt
148
+ - spec/fixtures/mixed_code_before.txt
149
+ - spec/fixtures/old_skool_after.txt
150
+ - spec/fixtures/old_skool_before.txt
113
151
  - spec/lib/junklet_spec.rb
152
+ - spec/lib/junklet_upgrade_parser_spec.rb
153
+ - spec/lib/line_spec.rb
114
154
  - spec/spec_helper.rb
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-