composable_fixtures 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be1032be623a2fbb0a11d939764f6be915dc90bb
4
+ data.tar.gz: 2a7cab596fd2911f8465c2fc1e5d6ff5dcb4cae5
5
+ SHA512:
6
+ metadata.gz: 508c0eb1a0ff441691deb96d6d3bb57d46baf7cfbe9a5401695ee190562169e8b20d2db09691078d956fbb2746757135aa90cbbfde662f82769d075144f8baa0
7
+ data.tar.gz: a73a64a659f0f89cfab02de0cb0b06e58e8fa1d48e99287195dd1fe676eb233052b2585577caf1895aa88d6091f4cc9c4513a50d24386648e977d3ffb8f7a2a4
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Optoro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # composable_fixtures
2
+
3
+ A [elight](http://github.com/elight) and [bhaibel](http://github.com/bhaibel) joint.
4
+
5
+ ## Installation
6
+
7
+ NOTE: Currently depends on rspec and rspec-rails
8
+
9
+ In your spec_helper, add the following:
10
+
11
+ ```ruby
12
+ class RSpec::Core::ExampleGroup
13
+ extend ComposableFixtures::ExampleGroupHelpers
14
+ end
15
+
16
+ require 'rspec/rails'
17
+ ```
18
+
19
+ You will also want ot add a FixtureSetDefinition. An example is given below.
20
+
21
+ ## Rough Example
22
+
23
+ ```ruby
24
+ FixtureSetDefinition.create do
25
+ set :normal_shipped, "spec/auditor/fixtures/normal_shipped"
26
+ set :normal_shipped_amazon, "spec/auditor/fixtures/normal_shipped_amazon"
27
+ set :multiple "spec/foo/fixtures", "spec/bar/fixtures"
28
+
29
+ compose :normal, :normal_shipped, :normal_shipped_amazon
30
+ compose :all_fixtures, :multiple, :normal
31
+ end
32
+
33
+ describe Foo do
34
+ # Any 'set' or 'compose' is a valid input and *only* loads those fixtures
35
+ use_composed_fixture_set :normal
36
+ fixtures :all
37
+ end
38
+ ```
39
+
40
+ ## Future direction
41
+
42
+ We envision something ala a factories.rb file for the `FixtureSetDefinition` that, similar to factories.rb,
43
+ could conceivably be defined over multiple files for sanity's sake. Beyond that, the goal is to keep this gem relatively simple.
44
+
45
+ We have a sister project under way internally for fixture generation from sanitized production/test data; however, it is not as yet ready for public release.
46
+
47
+ ## Contributing to composable_fixtures
48
+
49
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
50
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
51
+ * Fork the project.
52
+ * Start a feature/bugfix branch.
53
+ * Commit and push until you are happy with your contribution.
54
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
55
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
56
+
57
+ ## Copyright
58
+
59
+ Copyright (c) 2015 Optoro. See LICENSE.txt for
60
+ further details.
61
+
@@ -0,0 +1,32 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: composable_fixtures 0.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "composable_fixtures"
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Evan Light", "Betsy Haibel"]
14
+ s.date = "2015-01-30"
15
+ s.description = "Allows composing fixture sets"
16
+ s.email = "evan@tripledogdare.net"
17
+ s.files = %w[composable_fixtures.gemspec] + Dir['*.md', '*.txt', 'lib/**/*.rb']
18
+ s.homepage = "http://github.com/optoro/composable_fixtures"
19
+ s.licenses = ["MIT"]
20
+ s.rubygems_version = "2.2.2"
21
+ s.summary = "Allows composing fixture sets"
22
+
23
+ s.add_development_dependency("rspec", "~> 3.1")
24
+ s.add_development_dependency("bundler", "~> 1.0")
25
+ s.add_development_dependency("simplecov", ">= 0")
26
+ s.add_development_dependency("rspec-rails", ">= 3")
27
+ s.add_development_dependency("pry", ">= 0.10")
28
+
29
+ s.add_runtime_dependency("rspec", "~> 3.1")
30
+ s.add_runtime_dependency("rspec-rails", ">= 3")
31
+ end
32
+
@@ -0,0 +1,30 @@
1
+ module ComposableFixtures
2
+ class ComposableFixtureSetDefinition
3
+ include Enumerable
4
+
5
+ attr_reader :set_names
6
+
7
+ def initialize(composition_name, set_names)
8
+ @name, @set_names = composition_name, set_names
9
+ end
10
+
11
+ def each(&block)
12
+ @set_names.each(&block)
13
+ end
14
+
15
+
16
+ def as_filename_to_yaml
17
+ set_names = @set_names.dup
18
+ set_name = set_names.pop
19
+ set_def = FixtureSetRepository.instance.fetch(set_name)
20
+ composer = FixtureComposer.new(set_def.set_names)
21
+
22
+ set_names.reduce(composer) do |acc_composer, set_name|
23
+ set_def = FixtureSetRepository.instance.fetch(set_name)
24
+ composer.concat!(
25
+ FixtureComposer.new(set_def.set_names).as_filename_to_yaml
26
+ )
27
+ end.as_filename_to_yaml
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ module ComposableFixtures
2
+ class FixtureComposer
3
+ def initialize(fixture_names)
4
+ @fixture_names = fixture_names
5
+ @filename_to_concatd_fixtures = {}
6
+ end
7
+
8
+ def as_filename_to_yaml
9
+ @fixture_names.each do |fixture_name|
10
+ set_def = FixtureSetRepository.instance.fetch(fixture_name)
11
+ set_def.each do |fixture_set_path|
12
+ Dir.foreach(fixture_set_path) do |filename|
13
+ next if filename =~ /^\./
14
+ extract_fixture_from(fixture_set_path, filename)
15
+ end
16
+ end
17
+ end
18
+ @filename_to_concatd_fixtures
19
+ end
20
+
21
+ def extract_fixture_from(fixture_set_path, filename)
22
+ File.open(File.join(fixture_set_path, filename), "r") do |f|
23
+ contents = f.readlines
24
+
25
+ if @filename_to_concatd_fixtures.has_key?(filename)
26
+ # Remove "---" at top of YAML
27
+ contents.shift
28
+ else
29
+ # We haven't loaded any of this file yet so initialize it with a string
30
+ @filename_to_concatd_fixtures[filename] = ""
31
+ end
32
+
33
+ @filename_to_concatd_fixtures[filename] += contents.join("\n")
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,49 @@
1
+ require 'tmpdir'
2
+ require 'singleton'
3
+
4
+ module ComposableFixtures
5
+ class FixtureDirectory
6
+ include Singleton
7
+
8
+ class DirectoryAlreadyExistsError < StandardError; end
9
+ class DirectoryDoesntExistError < StandardError; end
10
+
11
+ def create
12
+ raise DirectoryAlreadyExistsError if @dir
13
+ @dir = Dir.mktmpdir
14
+ end
15
+
16
+ def destroy
17
+ raise DirectoryDoesntExistError unless @dir
18
+ FileUtils.remove_entry @dir
19
+ end
20
+
21
+ def write(name_to_fixtures)
22
+ name_to_fixtures.each do |(name, yaml)|
23
+ File.open(File.join(path, name), "w") do |f|
24
+ f.write yaml
25
+ end
26
+ end
27
+ end
28
+
29
+ def path
30
+ @dir.to_s
31
+ end
32
+
33
+ def self.create
34
+ instance.create
35
+ end
36
+
37
+ def self.write(fixtures)
38
+ instance.write(fixtures)
39
+ end
40
+
41
+ def self.destroy
42
+ instance.destroy
43
+ end
44
+
45
+ def self.path
46
+ instance.path
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ module ComposableFixtures
2
+ class FixtureSetDefinition
3
+ attr_reader :name, :paths
4
+
5
+ def self.create(name, paths)
6
+ FixtureSetRepository.instance.register(
7
+ name,
8
+ new(name, paths)
9
+ )
10
+ end
11
+
12
+ def each(&block)
13
+ @paths.each(&block)
14
+ end
15
+
16
+ def initialize(name, paths)
17
+ @name, @paths = name, paths
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,26 @@
1
+ require 'singleton'
2
+
3
+ module ComposableFixtures
4
+ class FixtureSetRepository
5
+ include Singleton
6
+ include Enumerable
7
+
8
+ def register(name, set_definition)
9
+ repository[name] = set_definition
10
+ end
11
+
12
+ def fetch(name)
13
+ repository.fetch(name)
14
+ end
15
+
16
+ def each(&block)
17
+ repository.values.each(&block)
18
+ end
19
+
20
+ private
21
+
22
+ def repository
23
+ @repository ||= {}
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ class RSpec::Core::ExampleGroup
2
+ extend ComposableFixtures::ExampleGroupHelpers
3
+ end
@@ -0,0 +1,22 @@
1
+ if defined?(Rails)
2
+ require 'rspec/rails'
3
+ else
4
+ # FIXME: This breaks when you go to access a fixture by name because the
5
+ # fixture_cache is nil
6
+ module Rails
7
+ module VERSION
8
+ STRING = "3.2.17"
9
+ end
10
+ end
11
+
12
+ require 'rspec/rails/adapters'
13
+ require 'rspec/rails/fixture_support'
14
+
15
+ RSpec.configure do |c|
16
+ c.include RSpec::Rails::FixtureSupport
17
+ c.add_setting :fixture_path
18
+ c.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
19
+ c.add_setting :use_instantiated_fixtures
20
+ c.add_setting :global_fixtures
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ require 'composable_fixtures/fixture_set_definition'
2
+ require 'composable_fixtures/fixture_set_repository'
3
+ require 'composable_fixtures/fixture_directory'
4
+ require 'composable_fixtures/fixture_composer'
5
+
6
+ module ComposableFixtures
7
+ module ExampleGroupHelpers
8
+ def use_composed_fixture_set(*fixtures)
9
+ FixtureDirectory.create
10
+ FixtureDirectory.write(
11
+ FixtureComposer.new(fixtures).as_filename_to_yaml
12
+ )
13
+
14
+ self.fixture_path = FixtureDirectory.path
15
+
16
+ after(:all) do
17
+ FixtureDirectory.destroy
18
+ end
19
+ end
20
+ end
21
+
22
+ def self.define(&block)
23
+ module_eval(&block)
24
+ end
25
+
26
+ def self.set(name, *fixture_set_paths)
27
+ FixtureSetDefinition.create(name, fixture_set_paths)
28
+ end
29
+
30
+ def self.compose(name, *set_names)
31
+ fixture_set_paths =
32
+ set_names.reduce([]) do |fixture_set_paths, set_name|
33
+ fixture_set_paths += FixtureSetRepository.instance.fetch(set_name).paths
34
+ end
35
+ set(name, *fixture_set_paths)
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ require 'tmpdir'
2
+ require 'singleton'
3
+
4
+ module ComposableFixtures
5
+ class FixtureDirectory
6
+ include Singleton
7
+
8
+ class DirectoryAlreadyExistsError < StandardError; end
9
+ class DirectoryDoesntExistError < StandardError; end
10
+
11
+ def create
12
+ raise DirectoryAlreadyExistsError if @dir
13
+ @dir = Dir.mktmpdir
14
+ end
15
+
16
+ def destroy
17
+ raise DirectoryDoesntExistError unless @dir
18
+ FileUtils.remove_entry @dir
19
+ end
20
+
21
+ def write
22
+ name_to_fixtures.each do |(name, yaml)|
23
+ File.open(File.join(path, name), "w") do |f|
24
+ f.write yaml
25
+ end
26
+ end
27
+ end
28
+
29
+ def path
30
+ @dir.to_s
31
+ end
32
+
33
+
34
+ def self.create
35
+ instance.create
36
+ end
37
+
38
+ def self.write(fixtures)
39
+ instance.write(fixtures)
40
+ end
41
+
42
+ def self.destroy
43
+ instance.destroy
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: composable_fixtures
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Evan Light
8
+ - Betsy Haibel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-01-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '3.1'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: simplecov
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0.10'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0.10'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '3.1'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '3.1'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec-rails
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '3'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '3'
112
+ description: Allows composing fixture sets
113
+ email: evan@tripledogdare.net
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - composable_fixtures.gemspec
119
+ - README.md
120
+ - LICENSE.txt
121
+ - lib/composable_fixtures/composable_fixture_set_definition.rb
122
+ - lib/composable_fixtures/fixture_composer.rb
123
+ - lib/composable_fixtures/fixture_directory.rb
124
+ - lib/composable_fixtures/fixture_set_definition.rb
125
+ - lib/composable_fixtures/fixture_set_repository.rb
126
+ - lib/composable_fixtures/rspec_integration.rb
127
+ - lib/composable_fixtures/rspec_rails_integration.rb
128
+ - lib/composable_fixtures.rb
129
+ - lib/fixture_directory.rb
130
+ homepage: http://github.com/optoro/composable_fixtures
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.0.3
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Allows composing fixture sets
154
+ test_files: []
155
+ has_rdoc: