junklet 0.9.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzhmYTIyOTAwZDQ0MzM0YTk4ZWUwZjQ3ODBmYjFjNDVmYWE3YzNiNg==
5
+ data.tar.gz: !binary |-
6
+ MDJjMjVlZjJmOWQ1NjBiZDU4MzI5ZDUzZjZmNDM2NDNmZTBhNjRlNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ODg2ODhiMmFmNGE2ZDQ2MjI2OTA4NmZhNDhlNDA1MTVhZDU0NTZhZDQzYjBl
10
+ NzlkNTg1ZDM2NzhmMjBjYjUyMWQ2NWVjNWE1OTIxYjhkYjU4MDQ1MmIwMjk1
11
+ MTllOWRhMWNiM2UwNzNkOTAwMTZiY2U5NDM3MThmYTZiN2Q3OGU=
12
+ data.tar.gz: !binary |-
13
+ YzE0NzVhYzEzM2QyN2ExMjAwMzk3NmVjOTk2NTc5MjhhODIzOTkyMjU3MzUz
14
+ OGM5MmY4YWQ2NTlhODQwODczZWIwMjUyZDU0NjYwZjJiMWVkN2MxMjRiMzI2
15
+ YTA0MTM5OTQ2OTQ0NDFiZjY1MDAxYzExMzFhMTZiYzRlZTMwNjc=
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in junklet.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ junklet (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ builder (3.2.2)
10
+ cucumber (1.3.18)
11
+ builder (>= 2.1.2)
12
+ diff-lcs (>= 1.1.3)
13
+ gherkin (~> 2.12)
14
+ multi_json (>= 1.7.5, < 2.0)
15
+ multi_test (>= 0.1.1)
16
+ diff-lcs (1.2.5)
17
+ gherkin (2.12.2)
18
+ multi_json (~> 1.3)
19
+ multi_json (1.10.1)
20
+ multi_test (0.1.1)
21
+ rake (10.4.2)
22
+ rspec (2.99.0)
23
+ rspec-core (~> 2.99.0)
24
+ rspec-expectations (~> 2.99.0)
25
+ rspec-mocks (~> 2.99.0)
26
+ rspec-core (2.99.2)
27
+ rspec-expectations (2.99.2)
28
+ diff-lcs (>= 1.1.3, < 2.0)
29
+ rspec-mocks (2.99.2)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.7)
36
+ cucumber
37
+ junklet!
38
+ rake (~> 10.0)
39
+ rspec (~> 2.0)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 CoverMyMeds
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # Junklet
2
+
3
+ Create tiny chunks of unique junk data in RSpec with `junklet :name`.
4
+
5
+ Junklet data is fixture data that:
6
+
7
+ * We essentially don't care about,
8
+ * But we might want to test for equality somewhere later,
9
+ * And we might need to be unique between runs in case a spec crashes
10
+ and SQLServer fails to clean up the test database
11
+
12
+ So,
13
+
14
+ * We want it to be easy to create junk data fields quickly and easily,
15
+ and
16
+ * If equality fails we want to be led to the offending field by the
17
+ error message and not just the line number in the stack trace.
18
+
19
+ # Background
20
+
21
+ At CoverMyMeds we have a legacy impingement that prevents us sometimes
22
+ from clearing out data from previous test runs. As a result we often
23
+ have required fields in tests that must be unique but are tested
24
+ elsewhere, so we don't really care about them in the current test
25
+ run. For the current test we just want to stub out that field with
26
+ something unique but we also want to communicate to the developer that
27
+ the contents of the field are not what we currently care about.
28
+
29
+ Currently we do this with `SecureRandom.uuid`, so we'll see code like
30
+ this frequently in RSpec:
31
+
32
+ ```ruby
33
+ let(:first_name) { SecureRandom.uuid }
34
+ let(:last_name) { SecureRandom.uuid }
35
+ let(:address) { SecureRandom.uuid }
36
+ let(:city) { SecureRandom.uuid }
37
+ let(:state) { SecureRandom.uuid }
38
+ let(:phone) { SecureRandom.uuid }
39
+ ```
40
+
41
+ ...etc. Later in the spec we'll often test against those stubs,
42
+ e.g. with `expect(user.first_name).to eq(first_name)` but this idiom
43
+ expresses that we only care about the equality, not the actual
44
+ contents.
45
+
46
+ Junklet seeks to improve the readability and conciseness of this
47
+ intention. One thing that bugs me about the above approach is that if
48
+ a weird regression bug appears and an unimportant field is the source
49
+ of a crash. So with Junklet I also wanted to add the ability to call
50
+ out the offending field by name. In theory we could just write
51
+ `let(:first_name) { 'first_name-' + SecureRandom.uuid }` but in
52
+ practice that creates duplication in the code and muddies the original
53
+ idiom of "uncared-about" data.
54
+
55
+ Enter Junklet:
56
+
57
+ ```ruby
58
+ junklet :first_name
59
+ junklet :last_name
60
+ junklet :address
61
+ junklet :city
62
+ junklet :state
63
+ junklet :phone
64
+ ```
65
+
66
+ Or, if you don't want the junklets to sprawl vertically,
67
+
68
+ ```ruby
69
+ junklet :first_name, :last_name, :address, :city, :state, :phone
70
+ ```
71
+
72
+ This will have the same effect as calling `let` on the named fields
73
+ and setting the fieldname and a UUID to be the memoized value.
74
+
75
+ No, `junklet!` is NOT also included here because it doesn't really
76
+ make sense until and unless we write custom generators.
77
+
78
+ # TODO
79
+
80
+ * Formats - The original motivation for Junklet is to encapsulate the
81
+ SecureRandom.uuid code into something meaningful and
82
+ intention-revealing. However, it only works for strings with no
83
+ formatting. If you have a field that DOES have a formatting
84
+ requirement, then you have to fall back on a real `let`
85
+ statement. I'd like Junklet to be able to provide common formatters
86
+ and/or accept formatters for fields with special values or
87
+ formats. So an email address could look like
88
+ 'email-junkuser@#{uuid}.com', or a currency field could contain a
89
+ random value from $0.00 to $99,999,999.00 (or some other equally
90
+ reasonable upper limit). A small signed int could contain -128 to
91
+ 127 and even a boolean could contain a random true/false value. You
92
+ could argue that this starts to lead towards nondeterministic tests
93
+ but the reality is the started heading there when we first started
94
+ making calls to SecureRandom. My thinking is that a call to
95
+ `junklet` could accept an optional hash and/or block that defines a
96
+ formatter and/or generator, and/or the configuration for Junklet
97
+ could accept definitions of domain-specific formatters that you want
98
+ to reuse throughout your project.
99
+
100
+ * True cucumber features - RSpec is tested with cucumber features that
101
+ express blocks of RSpec and then evaluate that the specs did what
102
+ was intended. The existing spec suite merely uses junklets and then
103
+ tests their side effects.
104
+
105
+ * RSpec 3.x support - Ideally the mechanism for adding the `junklet`
106
+ method is the same, but if not then a separate version would be nice
107
+ for building and testing RSpec 3 vs. 2. We need to support both, but
108
+ at the time of this writing the most pressing need is for
109
+ RSpec 2. Remember kids, "Enterprise" means "most of our money comes
110
+ from the legacy platform".
111
+
112
+ ## Installation
113
+
114
+ Add this line to your application's Gemfile:
115
+
116
+ ```ruby
117
+ gem 'junklet'
118
+ ```
119
+
120
+ And then execute:
121
+
122
+ $ bundle
123
+
124
+ Or install it yourself as:
125
+
126
+ $ gem install junklet
127
+
128
+ ## Usage
129
+
130
+ TODO: Write usage instructions here
131
+
132
+ ## Contributing
133
+
134
+ 1. Fork it ( https://github.com/[my-github-username]/junklet/fork )
135
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
136
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
137
+ 4. Push to the branch (`git push origin my-new-feature`)
138
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/junklet.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'junklet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "junklet"
8
+ spec.version = Junklet::VERSION
9
+ spec.authors = ["Dave Brady"]
10
+ spec.email = ["dbrady@covermymeds.com"]
11
+ spec.summary = "Easily create junk data for specs"
12
+ spec.description = "Works like let and let! for rspec, but creates unique random junk data"
13
+ spec.homepage = ""
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 2.0"
24
+ spec.add_development_dependency "cucumber"
25
+ end
@@ -0,0 +1,3 @@
1
+ module Junklet
2
+ VERSION = "0.9.0"
3
+ end
data/lib/junklet.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "junklet/version"
2
+
3
+ module RSpec
4
+ module Core
5
+ module MemoizedHelpers
6
+ module ClassMethods
7
+ def junklet(*args)
8
+ Array(args).each do |name|
9
+ let(name) { "#{name}-#{SecureRandom.uuid}" }
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Junklet do
4
+ specify { expect(Junklet).to be }
5
+
6
+ let(:regex) { /-[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/ }
7
+
8
+ describe '.junklet' do
9
+ context "with a single arg" do
10
+ junklet :junk
11
+
12
+ specify { expect(junk).to be }
13
+ specify { expect(junk).to match /^junk-/ }
14
+ specify { expect(junk).to match regex }
15
+
16
+ describe "memoization" do
17
+ specify { expect(junk).to eq(junk) }
18
+ end
19
+ end
20
+
21
+ context "with multiple args" do
22
+ junklet :junk, :toss, :crud, :crap
23
+
24
+ specify { expect(junk).to match /^junk-/ }
25
+ specify { expect(junk).to match regex }
26
+ specify { expect(toss).to match /^toss-/ }
27
+ specify { expect(toss).to match regex }
28
+ specify { expect(crud).to match /^crud-/ }
29
+ specify { expect(crud).to match regex }
30
+ specify { expect(crap).to match /^crap-/ }
31
+ specify { expect(crap).to match regex }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ # spec_helper.rb
2
+
3
+ require_relative '../lib/junklet'
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: junklet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Brady
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-07 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Works like let and let! for rspec, but creates unique random junk data
70
+ email:
71
+ - dbrady@covermymeds.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - junklet.gemspec
83
+ - lib/junklet.rb
84
+ - lib/junklet/version.rb
85
+ - spec/lib/junklet_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Easily create junk data for specs
111
+ test_files:
112
+ - spec/lib/junklet_spec.rb
113
+ - spec/spec_helper.rb