rspec-approvals 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/README.md +9 -5
- data/lib/rspec/approvals/approval.rb +19 -3
- data/lib/rspec/approvals/version.rb +1 -1
- data/spec/approval_spec.rb +2 -2
- data/spec/approvals/rspec_approvals_a_complex_object.approved.txt +1 -1
- data/spec/approvals/rspec_approvals_a_hash.approved.txt +3 -1
- data/spec/approvals/rspec_approvals_a_string.approved.txt +1 -1
- data/spec/approvals/rspec_approvals_an_array.approved.txt +4 -1
- data/spec/approvals_spec.rb +5 -3
- metadata +3 -3
data/README.md
CHANGED
@@ -5,10 +5,14 @@ Approvals are based on the idea of the *_golden master_*.
|
|
5
5
|
You take a snapshot of an object, and then compare all future
|
6
6
|
versions of the object to the snapshot.
|
7
7
|
|
8
|
-
|
8
|
+
Big hat tip to Llewellyn Falco who developed the approvals concept, as
|
9
|
+
well as the original approvals libraries (.NET, Java, Ruby, PHP,
|
10
|
+
probably others).
|
9
11
|
|
10
|
-
|
12
|
+
See [ApprovalTests](http://www.approvaltests.com) for videos and additional documentation about the general concept.
|
11
13
|
|
14
|
+
Also, check out Herding Code's podcast #117 http://t.co/GLn88R5 in
|
15
|
+
which Llewellyn Falco is interviewed about approvals.
|
12
16
|
|
13
17
|
## Configuration
|
14
18
|
|
@@ -32,11 +36,11 @@ The basic format of the approval is modeled after RSpec's `it`:
|
|
32
36
|
end
|
33
37
|
|
34
38
|
|
35
|
-
The `:
|
39
|
+
The `:inspect` method on the object will be used to generate the output for
|
36
40
|
the `*.received.txt` file. For custom objects you will need to override
|
37
|
-
the `:
|
41
|
+
the `:inspect` to get helpful output, rather than the default:
|
38
42
|
|
39
|
-
#<Object:0x0000010105ea40>
|
43
|
+
#<Object:0x0000010105ea40> # or whatever the object id is
|
40
44
|
|
41
45
|
The first time the specs are run, two files will be created:
|
42
46
|
|
@@ -5,6 +5,12 @@ module RSpec
|
|
5
5
|
|
6
6
|
class ReceivedDiffersError < RSpec::Expectations::ExpectationNotMetError; end
|
7
7
|
|
8
|
+
class EmptyApproval
|
9
|
+
def inspect
|
10
|
+
""
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
class Approval
|
9
15
|
|
10
16
|
def self.normalize(s)
|
@@ -26,7 +32,7 @@ module RSpec
|
|
26
32
|
:approved => approved_path,
|
27
33
|
}
|
28
34
|
|
29
|
-
write(:approved,
|
35
|
+
write(:approved, EmptyApproval.new) unless File.exists?(approved_path)
|
30
36
|
write(:received, received)
|
31
37
|
end
|
32
38
|
|
@@ -40,7 +46,17 @@ module RSpec
|
|
40
46
|
|
41
47
|
def write(suffix, contents)
|
42
48
|
File.open("#{@path}.#{suffix}.txt", 'w') do |f|
|
43
|
-
|
49
|
+
if contents.respond_to?(:each_pair)
|
50
|
+
contents.each_pair do |k,v|
|
51
|
+
f.write "#{k.inspect} => #{v.inspect}\n"
|
52
|
+
end
|
53
|
+
elsif contents.respond_to?(:each_with_index)
|
54
|
+
contents.each_with_index do |v,i|
|
55
|
+
f.write "[#{i.inspect}] #{v.inspect}\n"
|
56
|
+
end
|
57
|
+
else
|
58
|
+
f.write contents.inspect
|
59
|
+
end
|
44
60
|
end
|
45
61
|
end
|
46
62
|
|
@@ -56,7 +72,7 @@ module RSpec
|
|
56
72
|
#{approved_path}
|
57
73
|
|
58
74
|
If you like what you see in the *.received.txt file, you can approve it
|
59
|
-
|
75
|
+
by renaming it with the .approved.txt suffix.
|
60
76
|
|
61
77
|
mv #{received_path} #{approved_path}
|
62
78
|
|
data/spec/approval_spec.rb
CHANGED
@@ -88,7 +88,7 @@ The::Class \t \r\n \fname
|
|
88
88
|
approval = Approvals::Approval.new(example, 'oooh, shiney!')
|
89
89
|
|
90
90
|
File.exists?(@received_file).should be_true
|
91
|
-
File.read(@received_file).should eq("oooh, shiney!")
|
91
|
+
File.read(@received_file).should eq('"oooh, shiney!"')
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -144,7 +144,7 @@ The::Class \t \r\n \fname
|
|
144
144
|
#{approval.approved_path}
|
145
145
|
|
146
146
|
If you like what you see in the *.received.txt file, you can approve it
|
147
|
-
|
147
|
+
by renaming it with the .approved.txt suffix.
|
148
148
|
|
149
149
|
mv #{approval.received_path} #{approval.approved_path}
|
150
150
|
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
#<The World Says: Hello!>
|
@@ -1 +1 @@
|
|
1
|
-
We have, I fear, confused power with greatness.
|
1
|
+
"We have, I fear, confused power with greatness."
|
data/spec/approvals_spec.rb
CHANGED
@@ -36,7 +36,8 @@ describe Approvals do
|
|
36
36
|
:side => :dark,
|
37
37
|
:other_side => :light
|
38
38
|
},
|
39
|
-
:force => true
|
39
|
+
:force => true,
|
40
|
+
:evil => "undecided"
|
40
41
|
}
|
41
42
|
end
|
42
43
|
|
@@ -44,6 +45,7 @@ describe Approvals do
|
|
44
45
|
[
|
45
46
|
"abc",
|
46
47
|
123,
|
48
|
+
:zomg_fooooood,
|
47
49
|
%w(cheese burger ribs steak bacon)
|
48
50
|
]
|
49
51
|
end
|
@@ -55,10 +57,10 @@ describe Approvals do
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def hello.inspect
|
58
|
-
"
|
60
|
+
"#<The World Says: Hello!>"
|
59
61
|
end
|
60
62
|
|
61
|
-
hello # => output matches hello.
|
63
|
+
hello # => output matches hello.inspect
|
62
64
|
end
|
63
65
|
|
64
66
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Katrina Owen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-07-
|
17
|
+
date: 2011-07-27 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|