fakery 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53c31aa787a8c9a059340fa40fbf412a5d863f70
4
- data.tar.gz: f2adf0d385e2b3e090a66f1066edd0845d3813c7
3
+ metadata.gz: 5459515e0ea465c6584439c32d60489c1f1d5873
4
+ data.tar.gz: 7fea7ae849a853694108d840a3c2174ba8586ab2
5
5
  SHA512:
6
- metadata.gz: 4871051c30bc49d99887e3360567d62c00c5d5356e254b8d89c3a9c5584b5b330bf47fcbbfc8cfc5f4bd7d4a905d8abad7b0a961844c9d9fcbe61c0688bb96dc
7
- data.tar.gz: 36e6ad3ff98d671b51976521786e7a147440d3f656fb55ea8417a5a13c2deb5063872d7690d2d220ee354c9197e855fb88008ec705440999caabee59c3a0f239
6
+ metadata.gz: 9499de891351b88e108f90e551a776f96e541d44d0482faabf40c61068a94a188621fdcdc167645cb51ce48259dbebcfb6534e8eb9fc7b18cc140f2615fe381e
7
+ data.tar.gz: 881113d46f68162e8967247ff30d4ef08d964dfb205bec82ef6fd8766d769b9f9eccb6e3a39d29508ed2063937a5dfc920f902984abf5e01fb7e7e2138bf5b1f
data/.gitignore CHANGED
@@ -7,5 +7,6 @@
7
7
  Gemfile.lock
8
8
  coverage
9
9
  doc
10
+ errors.lst
10
11
  pkg
11
12
  tags
@@ -1,7 +1,15 @@
1
1
  rvm:
2
- - 2.1.5
2
+ - 2.1
3
+ - 2.2
4
+ - 2.3.1
5
+ - ruby-head
3
6
  matrix:
4
7
  allow_failures:
5
8
  - rvm: ruby-head
6
9
  env:
7
- - START_SIMPLECOV=1 CODECLIMATE_REPO_TOKEN=af3a05003c763bcee8abfdd7d7c46cc122c02ea09e5a71c3e16cf0a26685a851
10
+ - CODECLIMATE_REPO_TOKEN=af3a05003c763bcee8abfdd7d7c46cc122c02ea09e5a71c3e16cf0a26685a851
11
+
12
+ before_install:
13
+ - gem install bundler
14
+
15
+ sudo: false
data/Rakefile CHANGED
@@ -11,7 +11,8 @@ GemHadar do
11
11
  description "This library fakes ruby objects from JSON API responses for testing purposes."
12
12
  test_dir 'spec'
13
13
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
14
- '.ruby-version', '.AppleDouble', 'tags', '.DS_Store', '.utilsrc', 'doc'
14
+ '.ruby-version', '.AppleDouble', 'tags', '.DS_Store', '.utilsrc', 'doc',
15
+ 'errors.lst'
15
16
  readme 'README.md'
16
17
  title "#{name.camelize} -- "
17
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: fakery 0.1.0 ruby lib
2
+ # stub: fakery 0.2.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fakery"
6
- s.version = "0.1.0"
6
+ s.version = "0.2.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["betterplace Developers"]
11
- s.date = "2016-01-28"
11
+ s.date = "2016-05-26"
12
12
  s.description = "This library fakes ruby objects from JSON API responses for testing purposes."
13
13
  s.email = "developers@betterplace.org"
14
14
  s.extra_rdoc_files = ["README.md", "lib/fakery.rb", "lib/fakery/api.rb", "lib/fakery/api_error.rb", "lib/fakery/change.rb", "lib/fakery/fake.rb", "lib/fakery/fakery_error.rb", "lib/fakery/registry.rb", "lib/fakery/seeding.rb", "lib/fakery/version.rb", "lib/fakery/wrapping.rb"]
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.specification_version = 4
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<gem_hadar>, ["~> 1.3.1"])
26
+ s.add_development_dependency(%q<gem_hadar>, ["~> 1.7.1"])
27
27
  s.add_development_dependency(%q<simplecov>, [">= 0"])
28
28
  s.add_development_dependency(%q<rspec>, ["~> 3.0"])
29
29
  s.add_development_dependency(%q<rspec-nc>, [">= 0"])
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.add_runtime_dependency(%q<typhoeus>, ["~> 1.0"])
34
34
  s.add_runtime_dependency(%q<json>, ["~> 1.0"])
35
35
  else
36
- s.add_dependency(%q<gem_hadar>, ["~> 1.3.1"])
36
+ s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
37
37
  s.add_dependency(%q<simplecov>, [">= 0"])
38
38
  s.add_dependency(%q<rspec>, ["~> 3.0"])
39
39
  s.add_dependency(%q<rspec-nc>, [">= 0"])
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  s.add_dependency(%q<json>, ["~> 1.0"])
45
45
  end
46
46
  else
47
- s.add_dependency(%q<gem_hadar>, ["~> 1.3.1"])
47
+ s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
48
48
  s.add_dependency(%q<simplecov>, [">= 0"])
49
49
  s.add_dependency(%q<rspec>, ["~> 3.0"])
50
50
  s.add_dependency(%q<rspec-nc>, [">= 0"])
@@ -20,7 +20,7 @@ module Fakery
20
20
  extend Forwardable
21
21
 
22
22
  def_delegators :'Fakery::Registry', :register, :registered?, :build,
23
- :source
23
+ :source, :register_files
24
24
 
25
25
  def_delegators :'Fakery::Seeding', :seed, :reseed
26
26
 
@@ -70,7 +70,7 @@ class Fakery::Fake < JSON::GenericObject
70
70
 
71
71
  def register_as_ruby(register_name)
72
72
  register_name = register_name.to_sym
73
- result = <<EOT
73
+ <<EOT
74
74
  Fakery.register(#{register_name.inspect}, %{
75
75
  #{JSON.pretty_generate(self).gsub(/^/, ' ')}
76
76
  })
@@ -28,6 +28,17 @@ module Fakery::Registry
28
28
  registered_fakes[register_name] = Fakery::Fake.cast(fake)
29
29
  end
30
30
 
31
+ def register_files(*files)
32
+ files = files.flatten
33
+ puts "Registering fakes…"
34
+ for file in files
35
+ name = File.basename(file).sub('.json', '').to_sym
36
+ Fakery.register(name, File.read(file))
37
+ puts "Just registered the fake #{name.inspect}"
38
+ end
39
+ puts "Done."
40
+ end
41
+
31
42
  # Builds a the fake registered under the name +register_name+. All its fields
32
43
  # can be changed according to the names and values in the +with+ keyword
33
44
  # argument or later by using setters on the object.
@@ -1,6 +1,6 @@
1
1
  module Fakery
2
2
  # Fakery version
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -91,6 +91,13 @@ describe Fakery::Fake do
91
91
  expect(fake.name).to eq 'foo'
92
92
  end
93
93
 
94
+ it 'casts from an object implementing as_json method' do
95
+ object = double(as_json: { name: 'foo' })
96
+ casted = Fakery::Fake.cast(object)
97
+ expect(casted).to be_a Fakery::Fake
98
+ expect(casted.name).to eq 'foo'
99
+ end
100
+
94
101
  it 'raises an ArgumentError if it cannot cast' do
95
102
  expect { Fakery::Fake.cast(Object.new) }.to raise_error ArgumentError
96
103
  end
@@ -19,6 +19,12 @@ describe Fakery::Registry do
19
19
  Fakery.register 'foo', fake
20
20
  end
21
21
 
22
+ it 'can register files containing json as fakes' do
23
+ expect(File).to receive(:read).with('bar/foo.json').and_return fake.to_json
24
+ Fakery.register_files 'bar/foo.json'
25
+ expect(Fakery.build(:foo).name).to eq 'foo'
26
+ end
27
+
22
28
  context 'registered fake' do
23
29
  before :each do
24
30
  Fakery.register :foo, fake
@@ -4,14 +4,8 @@ if ENV['START_SIMPLECOV'].to_i == 1
4
4
  SimpleCov.start do
5
5
  add_filter "#{File.basename(File.dirname(__FILE__))}/"
6
6
  end
7
- end
8
- if ENV['CODECLIMATE_REPO_TOKEN']
9
- if ENV['START_SIMPLECOV']
10
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
11
- SimpleCov::Formatter::HTMLFormatter,
12
- CodeClimate::TestReporter::Formatter
13
- ]
14
- end
7
+ elsif ENV['CODECLIMATE_REPO_TOKEN']
8
+ require 'codeclimate-test-reporter'
15
9
  CodeClimate::TestReporter.start
16
10
  end
17
11
  require 'rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.1
19
+ version: 1.7.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.1
26
+ version: 1.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement