fixture_overlord 0.1.8

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27e8614d61ffca649fdc210a4ff480440c425bea
4
+ data.tar.gz: a28aa2db56b52305aac52532f9f2e49a63e01f73
5
+ SHA512:
6
+ metadata.gz: df52947dd10901e8acd31734415cb701622da273a33a769b9ba0915d302760851c02e6027f68f85932048cdaa3526a6455c547936e620a330d6295a34a1db8d5
7
+ data.tar.gz: 785e3d129597496325755add81309b1981bcfd1c5ca1cd1e9d914704014c264e467c5ae20fa348af729667f8312fe55d852a80bc4ac9dffe5e742c5fe363b844
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install:
5
+ - gem install bundler
6
+ notifications:
7
+ recipients:
8
+ - robert@codewranglers.org
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+ ruby "2.1.0"
3
+ gemspec
data/License.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Robert Evans
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/**/**/*_test.rb']
6
+ t.verbose = true
7
+ end
8
+
9
+ task :default => 'test'
data/Readme.mkd ADDED
@@ -0,0 +1,70 @@
1
+ # FixtureOverlord
2
+
3
+ * This is an Alpha version and is currently under heavy development.
4
+
5
+ [![Build Status](https://travis-ci.org/revans/fixture_overlord.png)](https://travis-ci.org/revans/fixture_overlord)
6
+
7
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/revans/fixture_overlord)
8
+
9
+ ## Usage
10
+
11
+ ### Setup
12
+
13
+ ```ruby
14
+ require 'minitest/autorun'
15
+
16
+ class MiniTest::Unit::TestCase
17
+ # include FixtureOverlord's Mixin
18
+ include FixtureOverlord
19
+
20
+ # add the fixture accessor that will define 1 method for each YAML file
21
+ # within {spec,test}/fixtures.
22
+ fixture_overloard :rule # set to :off to not define methods
23
+ end
24
+
25
+ # in an actual test file
26
+ class GameTest < MiniTest::Unit::TestCase
27
+
28
+ # build will initialize the model (in this case Game)
29
+ # e.g.
30
+ # Game.new(...)
31
+ #
32
+ def test_valid_attributes
33
+ refute_valid games(:tron).merge(name: nil).build
34
+ end
35
+
36
+ # changes name value to an empty string
37
+ # this is an alias to the merge method for e hash
38
+ #
39
+ # mock will create an OpenStruct Class with accessors
40
+ # to reference the data.
41
+ #
42
+ # e.g.
43
+ # OpenStruct.new(hashed_version_of_yaml_file)
44
+ #
45
+ def test_mock_game
46
+ mock = games(:tron).change(name: '').mock
47
+ assert_equal '', mock.name
48
+ end
49
+
50
+ # removes the key and value for the key named "name"
51
+ def test_missing_attributes
52
+ refute games(:tron).remove(:name).build.valid?
53
+ end
54
+
55
+ # create is executed on the model class, in this case Game
56
+ # e.g
57
+ # Game.create(...)
58
+ #
59
+ test "creating an entry in the database" do
60
+ assert_difference "Game.count", 1 do
61
+ games(:tron).create! # or games(:tron).create
62
+ end
63
+ end
64
+
65
+ # creates a hash
66
+ test "use a hash that has symbolized keys" do
67
+ assert games(:tron)
68
+ end
69
+ end
70
+ ```
data/bin/bundler ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bundler', 'bundler')
data/bin/erubis ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'erubis' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'erubis')
data/bin/rackup ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rackup' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'rackup')
data/bin/rails ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rails' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'rails')
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'rake')
data/bin/ri ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rdoc', 'ri')
data/bin/sprockets ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'sprockets' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'sprockets')
data/bin/thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'thor')
data/bin/tilt ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'tilt' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'tilt')
data/bin/tt ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'tt' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('fixture_overlord', 'tt')
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fixture_overlord/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "fixture_overlord"
8
+ gem.version = FixtureOverlord.version
9
+ gem.authors = ["Robert Evans"]
10
+ gem.email = ["robert@codewranglers.org"]
11
+ gem.description = %q{A Rails Gem for handling Fixtures without a database. Allows mocks, stubs, hashes, model object, and inserting into the database when you want it to. No need for the bloat of FactoryGirl or other Object Factory Gems.}
12
+ gem.summary = %q{Handling Fixtures the right way, within a Rails application.}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_runtime_dependency "activesupport", ">= 4.1.0.beta1"
22
+
23
+ gem.add_development_dependency "rake"
24
+ gem.add_development_dependency "rdoc"
25
+ gem.add_development_dependency "minitest"
26
+ end
@@ -0,0 +1,40 @@
1
+ require_relative "read_fixture"
2
+ require_relative "helpers"
3
+ require 'pathname'
4
+
5
+ module FixtureOverlord
6
+ module FixtureAccessor
7
+ extend self
8
+
9
+ def fixture_overlord(setting = nil)
10
+ return unless setting.to_sym == :rule
11
+ yaml_files.each do |yaml|
12
+
13
+ # creates the hash version of the model
14
+ define_method(yaml_filename(yaml)) do |key|
15
+ hash = FixtureOverlord.read_fixture(yaml, key)
16
+ hash.yaml_file = Helpers.yaml_filename(yaml)
17
+ hash
18
+ end
19
+
20
+ end
21
+ end
22
+
23
+ def root
24
+ @root ||= ::Pathname.new(Dir.pwd)
25
+ end
26
+
27
+ private
28
+
29
+ # glob all yml files from their respective fixtures location
30
+ def yaml_files
31
+ Dir.glob(root.join("{test,spec}/fixtures/**/*.{yaml,yml}").to_s)
32
+ end
33
+
34
+ # reading the yaml filename
35
+ def yaml_filename(file)
36
+ ::File.basename(file).split('.').first
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,75 @@
1
+ require 'ostruct'
2
+ require_relative 'mock'
3
+ require_relative 'model'
4
+ require_relative 'helpers'
5
+
6
+ # Hashish
7
+ #
8
+ # === About
9
+ #
10
+ # Hashish is an over-glorified Hash with a few extra special methods to make it easier
11
+ # to work with within FixtureOverlord. Things like +symbolize_keys+, which does a deep
12
+ # symbolization on all keys within the given hash help create a predictable hash to work
13
+ # with.
14
+ #
15
+ module FixtureOverlord
16
+ class Hashish < ::Hash
17
+ attr_accessor :yaml_file
18
+
19
+ def mock
20
+ Mock.setup(self)
21
+ end
22
+
23
+ def model
24
+ Model.init(self, yaml_file)
25
+ end
26
+
27
+ def create
28
+ Model.create(self, yaml_file)
29
+ end
30
+ alias :create! :create
31
+
32
+ def build
33
+ Model.init(self, yaml_file)
34
+ end
35
+
36
+ def symbolize_keys(hash = self)
37
+ results = case hash
38
+ when Array
39
+ symbolize_array_keys(hash)
40
+ when Hash
41
+ symbolize_hash_keys(hash)
42
+ else
43
+ hash
44
+ end
45
+ Hashish[results]
46
+ end
47
+
48
+ private
49
+
50
+ def symbolize_array_keys(array)
51
+ array.inject([]) do |result, value|
52
+ result << case value
53
+ when Hash, Array
54
+ symbolize_keys(value)
55
+ else
56
+ value
57
+ end
58
+ result
59
+ end
60
+ end
61
+
62
+ def symbolize_hash_keys(hash)
63
+ hash.inject({}) do |result, (key,value)|
64
+ nval = case value
65
+ when Hash, Array
66
+ symbolize_keys(value)
67
+ else
68
+ value
69
+ end
70
+ result[key.downcase.to_sym] = nval
71
+ result
72
+ end
73
+ end
74
+ end
75
+ end