yockeries 0.0.2 → 0.0.3
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.
- data/benchmarks/open_struct_vs_struct.rb +21 -0
- data/lib/yockeries.rb +6 -5
- data/test/yockeries_test.rb +11 -5
- data/yockeries.gemspec +1 -1
- metadata +3 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'benchmark'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
require_relative '../lib/yockeries'
|
|
4
|
+
|
|
5
|
+
REP = 100000
|
|
6
|
+
hash = {'user_1' => { 'name' => 'robert', 'email' => 'robert@example.com' },
|
|
7
|
+
'user_2' => { 'name' => 'tyler', 'email' => 'ty@example.com' } }
|
|
8
|
+
|
|
9
|
+
Benchmark.bm 20 do |x|
|
|
10
|
+
x.report 'Mock with an OpenStruct' do
|
|
11
|
+
REP.times do |index|
|
|
12
|
+
OpenStruct.new(Yockeries::YockHash.new(hash).get('user_1'))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
x.report 'Mock with a Struct ' do
|
|
17
|
+
REP.times do |index|
|
|
18
|
+
Yockeries::YockHash.new(hash).mock_for('user_1')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/yockeries.rb
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
|
-
require 'ostruct'
|
|
3
2
|
|
|
4
3
|
module Yockeries
|
|
5
4
|
class YockHash < Hash
|
|
5
|
+
attr_reader :hash
|
|
6
|
+
|
|
6
7
|
def initialize(hash = {})
|
|
7
8
|
@hash = symbolize_keys(hash)
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def get(name)
|
|
11
|
-
|
|
12
|
+
hash[name.to_sym]
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def mock_for(name)
|
|
15
|
-
|
|
16
|
+
hashed_mock = get(name)
|
|
17
|
+
::Struct.new( *(k=hashed_mock.keys)).new( *hashed_mock.values_at(*k) )
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
private
|
|
@@ -58,8 +60,7 @@ module Yockeries
|
|
|
58
60
|
|
|
59
61
|
module Loader
|
|
60
62
|
def fixture(filename)
|
|
61
|
-
|
|
62
|
-
file = Dir.glob("#{dir}/fixtures/#{filename}.{yaml,yml}").first
|
|
63
|
+
file = Dir.glob("{test,spec}/fixtures/#{filename}.{yaml,yml}").first
|
|
63
64
|
::Yockeries::YockHash.new(YAML.load_file(file))
|
|
64
65
|
end
|
|
65
66
|
end
|
data/test/yockeries_test.rb
CHANGED
|
@@ -22,12 +22,18 @@ module Yockeries
|
|
|
22
22
|
subject.get('user_2')[:name].must_equal 'tyler'
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
subject.mock_for('user_1')
|
|
27
|
-
|
|
25
|
+
describe "mocks" do
|
|
26
|
+
let(:mock) { subject.mock_for('user_1') }
|
|
27
|
+
|
|
28
|
+
it 'will return a mock' do
|
|
29
|
+
mock.kind_of?(Struct).must_equal true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'mocks will imitate an object' do
|
|
33
|
+
mock.name.must_equal 'robert'
|
|
34
|
+
mock.email.must_equal 'robert@example.com'
|
|
35
|
+
end
|
|
28
36
|
|
|
29
|
-
it 'mocks will imitate an object' do
|
|
30
|
-
subject.mock_for('user_1').name.must_equal 'robert'
|
|
31
37
|
end
|
|
32
38
|
end
|
|
33
39
|
|
data/yockeries.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |gem|
|
|
6
6
|
gem.name = "yockeries"
|
|
7
|
-
gem.version = '0.0.
|
|
7
|
+
gem.version = '0.0.3'
|
|
8
8
|
gem.authors = ["Robert Evans"]
|
|
9
9
|
gem.email = ["robert@codewranglers.org"]
|
|
10
10
|
gem.description = %q{Use Ruby Fixtures to create mocks or use in place of factories to create objects}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yockeries
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-11-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Use Ruby Fixtures to create mocks or use in place of factories to create
|
|
15
15
|
objects
|
|
@@ -24,6 +24,7 @@ files:
|
|
|
24
24
|
- LICENSE.txt
|
|
25
25
|
- README.rdoc
|
|
26
26
|
- Rakefile
|
|
27
|
+
- benchmarks/open_struct_vs_struct.rb
|
|
27
28
|
- lib/yockeries.rb
|
|
28
29
|
- test/fixtures/cow.yml
|
|
29
30
|
- test/fixtures/monkey.yaml
|