polaroid 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a8763fe87a6c9ee53c561598522032c5fc8cb1e
4
+ data.tar.gz: 8c47aaaba2d6f15ea7e8ce2489fc5cdfea84b7ef
5
+ SHA512:
6
+ metadata.gz: 136cfacbbe47466f4bcd335c94d00cef7745c3dbe505284fbd85132c7663e5ef05e027974f8c7d4ca572cd21fc8f669226cb46dc8e344711015c2298cc27023f
7
+ data.tar.gz: 4523e17ffa547f4cd3d56a0d17a650cd4e17012c5ca4aabdf0d726e8ce888db84784a936f68013f7513c9c4ed5b6c8d061bcf37dd480b1c2303d4e91047efc6a
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
19
+ .ruby-gemset
data/README.md CHANGED
@@ -91,7 +91,7 @@ Of course you do. So the `take_snapshot` and `build_from_snapshot` methods also
91
91
 
92
92
  ```ruby
93
93
  pat = Person.new('Patrick', 25, ['beer', 'coffee', 'ramen', 'pie'])
94
- json_snapshot = snapshot.take_snapshot(pat, :json)
94
+ json_snapshot = pat.take_snapshot(:json)
95
95
  # => "{\"name\":\"Patrick\",\"age\":25,\"favorite_drinks\":[\"beer\",\"coffee\"]}"
96
96
  Person.build_from_snapshot(json_snapshot, :json)
97
97
  # => #<struct Person::Snapshot name="Patrick", age=25, favorite_drinks=["beer", "coffee"]>
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = Dir[File.join(File.dirname(__FILE__), 'test/**/*test.rb')]
7
+ end
@@ -1,6 +1,7 @@
1
- class Polaroid < Module
1
+ require 'json'
2
+ require 'immutable_struct'
2
3
 
3
- VERSION = "0.0.4"
4
+ class Polaroid < Module
4
5
 
5
6
  def initialize(*messages)
6
7
  @messages = messages
@@ -0,0 +1,3 @@
1
+ class Polaroid < Module
2
+ VERSION = "0.0.5"
3
+ end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'polaroid'
4
+ require 'polaroid/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "polaroid"
@@ -15,12 +15,13 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0")
18
- # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
19
  spec.require_paths = ["lib"]
21
20
 
22
21
  spec.add_development_dependency "bundler", "~> 1.5"
23
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest-reporters", "~> 1.1"
24
+ spec.add_development_dependency "turn-again-reporter", "~> 1.1", ">= 1.1.0"
24
25
 
25
26
  spec.add_runtime_dependency "immutable_struct", "~> 1.1"
26
27
  spec.add_runtime_dependency "json", "~> 1.8"
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+ require 'sample_implementations/person'
3
+
4
+ class PolaroidTest < Minitest::Test
5
+
6
+
7
+ test "simple hash snapshot" do
8
+ pat = Person.new("Patrick", 25, ['beer', 'coffee', 'ramen', 'pie'])
9
+ expected = { name: "Patrick", age: 25, favorite_drinks: ['beer', 'coffee'] }
10
+
11
+ assert_equal(expected, pat.take_snapshot)
12
+ end
13
+
14
+
15
+ test "can restore from a snapshot" do
16
+ snapshot = { name: "Patrick", age: 25, favorite_drinks: ['beer', 'coffee'] }
17
+ pat = Person.build_from_snapshot(snapshot)
18
+
19
+ assert_equal("Patrick", pat.name)
20
+ assert_equal(25, pat.age)
21
+ assert_equal(['beer', 'coffee'], pat.favorite_drinks)
22
+ end
23
+
24
+
25
+ test "objects restored from snapshot do not respond to messages not captured" do
26
+ snapshot = { name: "Patrick", age: 25, favorite_drinks: ['beer', 'coffee'] }
27
+ pat = Person.build_from_snapshot(snapshot)
28
+ will_respond_to = [:name, :age, :favorite_drinks]
29
+ wont_respond_to = [:favorite_foods, :drink?, :food?, :favorites]
30
+
31
+ will_respond_to.each do |msg|
32
+ assert(pat.respond_to?(msg))
33
+ end
34
+ wont_respond_to.each do |msg|
35
+ refute(pat.respond_to?(msg))
36
+ end
37
+ end
38
+
39
+ ##
40
+ # Testing the string-equality of direct JSON output is not the optimal manner of
41
+ # testing the output of this, as it would bind this check to the specific output
42
+ # format of a particular JSON library's internal choices on formatting, whereas
43
+ # JSON is flexible to some amount of whitespace.
44
+ test "json snapshot parses back to the correct value" do
45
+ pat = Person.new("Patrick", 25, ['beer', 'coffee', 'ramen', 'pie'])
46
+ snapshot = pat.take_snapshot(:json)
47
+ # JSON will come back with string keys, not symbols
48
+ expected = { 'name' => "Patrick", 'age' => 25, 'favorite_drinks' => ['beer', 'coffee'] }
49
+ parsed = JSON.parse(snapshot)
50
+
51
+ assert_equal(expected, parsed)
52
+ end
53
+
54
+
55
+ test "objects can be restored from a json snapshot" do
56
+ snapshot = "{\"name\":\"Patrick\",\"age\":25,\"favorite_drinks\":[\"beer\",\"coffee\"]}"
57
+ pat = Person.build_from_snapshot(snapshot, :json)
58
+
59
+ assert_equal("Patrick", pat.name)
60
+ assert_equal(25, pat.age)
61
+ assert_equal(['beer', 'coffee'], pat.favorite_drinks)
62
+ end
63
+
64
+ end
@@ -0,0 +1,27 @@
1
+ class Person
2
+ include Polaroid.new(:name, :age, :favorite_drinks)
3
+
4
+ attr_reader :name, :age, :favorites
5
+
6
+ def initialize(name, age, favorites)
7
+ @name = name
8
+ @age = age
9
+ @favorites = favorites
10
+ end
11
+
12
+ def favorite_drinks
13
+ favorites.select { |fav| drink?(fav) }
14
+ end
15
+
16
+ def favorite_foods
17
+ favorites.select { |fav| food?(fav) }
18
+ end
19
+
20
+ def drink?(str)
21
+ %w[coffee beer wine tea water juice].include?(str)
22
+ end
23
+
24
+ def food?(str)
25
+ %w[omelete burrito ramen pie yogurt].include?(str)
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'minitest/reporters'
4
+ require 'minitest/reporters/turn_again_reporter'
5
+
6
+ Minitest::Reporters.use!(Minitest::Reporters::TurnAgainReporter.new)
7
+
8
+ require 'polaroid'
9
+
10
+ ##
11
+ # Blatantly stolen from ActiveSupport::Testing::Declarative
12
+ # Allows for test files such as
13
+ # test "verify something" do
14
+ # ...
15
+ # end
16
+ # which become methods named test_verify_something, leaving a visual difference
17
+ # between tests themselves and any helper methods declared in the usual
18
+ # manner of `def some_helper_method`.
19
+ module DeclarativeTests
20
+ def test(name, &block)
21
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
22
+ defined = instance_method(test_name) rescue false
23
+ raise "#{test_name} is already defined in #{self}" if defined
24
+ if block_given?
25
+ define_method(test_name, &block)
26
+ else
27
+ define_method(test_name) do
28
+ flunk "No implementation provided for #{name}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ class Minitest::Test
35
+ extend DeclarativeTests
36
+ end
metadata CHANGED
@@ -1,78 +1,103 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polaroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Paul Kwiatkowski
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2016-04-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.5'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.5'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-reporters
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turn-again-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.1.0
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.1.0
46
75
  - !ruby/object:Gem::Dependency
47
76
  name: immutable_struct
48
77
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
78
  requirements:
51
- - - ~>
79
+ - - "~>"
52
80
  - !ruby/object:Gem::Version
53
81
  version: '1.1'
54
82
  type: :runtime
55
83
  prerelease: false
56
84
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
85
  requirements:
59
- - - ~>
86
+ - - "~>"
60
87
  - !ruby/object:Gem::Version
61
88
  version: '1.1'
62
89
  - !ruby/object:Gem::Dependency
63
90
  name: json
64
91
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
92
  requirements:
67
- - - ~>
93
+ - - "~>"
68
94
  - !ruby/object:Gem::Version
69
95
  version: '1.8'
70
96
  type: :runtime
71
97
  prerelease: false
72
98
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
99
  requirements:
75
- - - ~>
100
+ - - "~>"
76
101
  - !ruby/object:Gem::Version
77
102
  version: '1.8'
78
103
  description: Polaroid provides shortcuts to capture the state of a Ruby object, and
@@ -85,37 +110,43 @@ executables: []
85
110
  extensions: []
86
111
  extra_rdoc_files: []
87
112
  files:
88
- - .gitignore
113
+ - ".gitignore"
89
114
  - Gemfile
90
115
  - LICENSE.txt
91
116
  - README.md
92
117
  - Rakefile
93
118
  - lib/polaroid.rb
119
+ - lib/polaroid/version.rb
94
120
  - polaroid.gemspec
121
+ - test/polaroid_test.rb
122
+ - test/sample_implementations/person.rb
123
+ - test/test_helper.rb
95
124
  homepage: https://github.com/swifthand/polaroid
96
125
  licenses:
97
126
  - MIT
127
+ metadata: {}
98
128
  post_install_message:
99
129
  rdoc_options: []
100
130
  require_paths:
101
131
  - lib
102
132
  required_ruby_version: !ruby/object:Gem::Requirement
103
- none: false
104
133
  requirements:
105
- - - ! '>='
134
+ - - ">="
106
135
  - !ruby/object:Gem::Version
107
136
  version: '0'
108
137
  required_rubygems_version: !ruby/object:Gem::Requirement
109
- none: false
110
138
  requirements:
111
- - - ! '>='
139
+ - - ">="
112
140
  - !ruby/object:Gem::Version
113
141
  version: '0'
114
142
  requirements: []
115
143
  rubyforge_project:
116
- rubygems_version: 1.8.25
144
+ rubygems_version: 2.4.8
117
145
  signing_key:
118
- specification_version: 3
146
+ specification_version: 4
119
147
  summary: Polaroid provides shortcuts to capture the state of a Ruby object, and can
120
148
  construct a fake object later to mimic that state.
121
- test_files: []
149
+ test_files:
150
+ - test/polaroid_test.rb
151
+ - test/sample_implementations/person.rb
152
+ - test/test_helper.rb