br-approvals 0.0.22
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +71 -0
- data/Gemfile +6 -0
- data/License.txt +22 -0
- data/README.md +263 -0
- data/Rakefile +6 -0
- data/approvals.gemspec +29 -0
- data/bin/approvals +8 -0
- data/ext/mkrf_conf.rb +22 -0
- data/lib/approvals.rb +33 -0
- data/lib/approvals/approval.rb +144 -0
- data/lib/approvals/cli.rb +36 -0
- data/lib/approvals/configuration.rb +29 -0
- data/lib/approvals/dotfile.rb +33 -0
- data/lib/approvals/dsl.rb +7 -0
- data/lib/approvals/error.rb +21 -0
- data/lib/approvals/executable.rb +18 -0
- data/lib/approvals/extensions/rspec.rb +13 -0
- data/lib/approvals/extensions/rspec/dsl.rb +44 -0
- data/lib/approvals/filter.rb +45 -0
- data/lib/approvals/namers/default_namer.rb +20 -0
- data/lib/approvals/namers/directory_namer.rb +30 -0
- data/lib/approvals/namers/rspec_namer.rb +32 -0
- data/lib/approvals/reporters.rb +14 -0
- data/lib/approvals/reporters/diff_reporter/diffmerge_reporter.rb +18 -0
- data/lib/approvals/reporters/diff_reporter/opendiff_reporter.rb +18 -0
- data/lib/approvals/reporters/diff_reporter/tortoisediff_reporter.rb +18 -0
- data/lib/approvals/reporters/diff_reporter/vimdiff_reporter.rb +18 -0
- data/lib/approvals/reporters/filelauncher_reporter.rb +18 -0
- data/lib/approvals/reporters/first_working_reporter.rb +21 -0
- data/lib/approvals/reporters/image_reporter.rb +13 -0
- data/lib/approvals/reporters/image_reporter/html_image_reporter.rb +35 -0
- data/lib/approvals/reporters/image_reporter/image_magick_reporter.rb +20 -0
- data/lib/approvals/reporters/launcher.rb +49 -0
- data/lib/approvals/reporters/reporter.rb +30 -0
- data/lib/approvals/rspec.rb +4 -0
- data/lib/approvals/scrubber.rb +43 -0
- data/lib/approvals/system_command.rb +13 -0
- data/lib/approvals/version.rb +3 -0
- data/lib/approvals/writer.rb +39 -0
- data/lib/approvals/writers/array_writer.rb +17 -0
- data/lib/approvals/writers/binary_writer.rb +49 -0
- data/lib/approvals/writers/hash_writer.rb +20 -0
- data/lib/approvals/writers/html_writer.rb +15 -0
- data/lib/approvals/writers/json_writer.rb +31 -0
- data/lib/approvals/writers/text_writer.rb +21 -0
- data/lib/approvals/writers/xml_writer.rb +15 -0
- data/spec/approvals_spec.rb +172 -0
- data/spec/configuration_spec.rb +28 -0
- data/spec/dotfile_spec.rb +22 -0
- data/spec/executable_spec.rb +17 -0
- data/spec/extensions/rspec_approvals_spec.rb +105 -0
- data/spec/filter_spec.rb +123 -0
- data/spec/fixtures/approvals/approvals_custom_writer_verifies_a_complex_object.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_passes_approved_files_through_erb.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_passes_the_received_files_through_erb.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_supports_excluded_keys_option_also_supports_an_array_of_hashes.approved.json +10 -0
- data/spec/fixtures/approvals/approvals_supports_excluded_keys_option_supports_the_array_writer.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_supports_excluded_keys_option_supports_the_hash_writer.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_supports_excluded_keys_option_verifies_json_with_excluded_keys.approved.json +8 -0
- data/spec/fixtures/approvals/approvals_verifies_a_complex_object.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_verifies_a_hash.approved.txt +6 -0
- data/spec/fixtures/approvals/approvals_verifies_a_malformed_html_fragment.approved.html +11 -0
- data/spec/fixtures/approvals/approvals_verifies_a_string.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_verifies_an_array.approved.txt +4 -0
- data/spec/fixtures/approvals/approvals_verifies_an_array_as_json_when_format_is_set_to_json.approved.json +10 -0
- data/spec/fixtures/approvals/approvals_verifies_an_executable.approved.txt +1 -0
- data/spec/fixtures/approvals/approvals_verifies_html.approved.html +11 -0
- data/spec/fixtures/approvals/approvals_verifies_json.approved.json +7 -0
- data/spec/fixtures/approvals/approvals_verifies_json_and_is_newline_agnostic.approved.json +7 -0
- data/spec/fixtures/approvals/approvals_verifies_xml.approved.xml +9 -0
- data/spec/fixtures/approvals/verifications_a_string.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_a_complex_object.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_a_failure.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_a_failure_diff.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_a_string.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_an_array.approved.txt +4 -0
- data/spec/fixtures/approvals/verifies_an_executable.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_directory/a_complex_object.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_directory/a_failure.approved.txt +0 -0
- data/spec/fixtures/approvals/verifies_directory/a_failure_diff.approved.txt +0 -0
- data/spec/fixtures/approvals/verifies_directory/a_string.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_directory/an_array.approved.txt +4 -0
- data/spec/fixtures/approvals/verifies_directory/an_executable.approved.txt +1 -0
- data/spec/fixtures/approvals/verifies_directory/html.approved.html +11 -0
- data/spec/fixtures/approvals/verifies_directory/json.approved.json +7 -0
- data/spec/fixtures/approvals/verifies_directory/xml.approved.xml +9 -0
- data/spec/fixtures/approvals/verifies_html.approved.html +11 -0
- data/spec/fixtures/approvals/verifies_json.approved.json +7 -0
- data/spec/fixtures/approvals/verifies_xml.approved.xml +9 -0
- data/spec/fixtures/one.png +0 -0
- data/spec/fixtures/one.txt +1 -0
- data/spec/fixtures/two.png +0 -0
- data/spec/fixtures/two.txt +1 -0
- data/spec/namers/default_namer_spec.rb +37 -0
- data/spec/namers/directory_namer_spec.rb +31 -0
- data/spec/namers/rspec_namer_spec.rb +30 -0
- data/spec/namers_spec.rb +16 -0
- data/spec/reporters/first_working_reporter_spec.rb +30 -0
- data/spec/reporters/html_image_reporter_spec.rb +22 -0
- data/spec/reporters/image_magick_reporter_spec.rb +16 -0
- data/spec/reporters/launcher_spec.rb +24 -0
- data/spec/reporters/opendiff_reporter_spec.rb +15 -0
- data/spec/reporters/reporter_spec.rb +21 -0
- data/spec/scrubber_spec.rb +26 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/system_command_spec.rb +13 -0
- metadata +196 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b63647cada9073bef605592e7b020c68a865690f
|
4
|
+
data.tar.gz: fa78ac98c6771a7de12e81d3d100a67c09709552
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe40cb6326244d6370509a6274f8f12aa9c59bb44b810e505486356113184d8934e7b59cb54f7afae26db120fee8bd714e54c2b6d24274ad095736559cc63cc5
|
7
|
+
data.tar.gz: ee4349658a39c61b03eb309cf1617f93c5a13c9ad7fb3df5fd18c906e4c39568d8b3080551580b270831eb3a54049f6e581f0d100f45318bbc33ed6ea3c32797
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### Next Release
|
4
|
+
|
5
|
+
* Your contribution here
|
6
|
+
|
7
|
+
### v0.0.22 (2015-10-22)
|
8
|
+
|
9
|
+
* Fix bug in non-binary comparisons.
|
10
|
+
|
11
|
+
### v0.0.21 (2015-10-12)
|
12
|
+
|
13
|
+
* [#64](https://github.com/kytrinyx/approvals/pull/64) Silence deprecation warnings - [@tmock12](https://github.com/tmock12)
|
14
|
+
* Fixed typos and replaced a deprecated standard library method call.
|
15
|
+
|
16
|
+
### v0.0.20 (2015-04-21)
|
17
|
+
|
18
|
+
* [#63](https://github.com/kytrinyx/approvals/issues/62) Make CLI --ask compatible with new or old .approval file. - [@kytrinyx](https://github.com/kytrinyx)
|
19
|
+
|
20
|
+
### v0.0.19 (2015-04-20)
|
21
|
+
|
22
|
+
* [#62](https://github.com/kytrinyx/approvals/issues/62) Fix bug in CLI with --ask option that deletes approval file instead of overwriting it. - [@kytrinyx](https://github.com/kytrinyx)
|
23
|
+
|
24
|
+
### v0.0.18 (2015-04-18)
|
25
|
+
|
26
|
+
- Greatly improve output on failure (Show the diff even if approved file is missing, don't complain if there's no .approvals file, print diff command before showing each diff for better context, and reverse the order of the arguments to the diff so that the additions/removals make sense). - [@randycoulman](https://github.com/randycoulman)
|
27
|
+
- General improvements (fix typos, replace PNG badges with SVG ones) - [@jamonholmgren](https://github.com/jamonholmgren), [@olivierlacan](https://github.com/olivierlacan)
|
28
|
+
|
29
|
+
### v0.0.17 (2014-10-10)
|
30
|
+
|
31
|
+
- [#55](https://github.com/kytrinyx/approvals/pull/55) Upgrade to RSpec 3.1 - [@Willianvdv](https://github.com/Willianvdv)
|
32
|
+
|
33
|
+
### v0.0.16 (2014-05-19)
|
34
|
+
|
35
|
+
- General improvements (refactoring, simplify travis build, fix whitespace issues) - [@zph](https://github.com/zph), [@markijbema](https://github.com/markijbema)
|
36
|
+
- Ignore trailing whitespace when making assertions. - [@kytrinyx](https://github.com/kytrinyx)
|
37
|
+
|
38
|
+
### v0.0.15 (2014-04-05)
|
39
|
+
|
40
|
+
- [#46](https://github.com/kytrinyx/approvals/pull/46) Improve handling of malformed HTML. - [@hotgazpacho](https://github.com/hotgazpacho)
|
41
|
+
|
42
|
+
### v0.0.14 (2014-04-05)
|
43
|
+
|
44
|
+
- [#48](https://github.com/kytrinyx/approvals/pull/48) Fix CLI namespace clash. - [@zph](https://github.com/zph)
|
45
|
+
|
46
|
+
### v0.0.13 (2014-03-10)
|
47
|
+
|
48
|
+
- Allow verifying hashes and arrays as json. - [@markijbema](https://github.com/markijbema)
|
49
|
+
- Add support for RSpec 3.0. - [@markijbema](https://github.com/markijbema)
|
50
|
+
- General improvements (documentation, README, refactoring). - [@markijbema](https://github.com/markijbema), [@kytrinyx](https://github.com/kytrinyx)
|
51
|
+
|
52
|
+
### v0.0.12 (2014-02-16)
|
53
|
+
|
54
|
+
- [#34](https://github.com/kytrinyx/approvals/pull/34) Make default formatter configurable. - [@markijbema](https://github.com/markijbema)
|
55
|
+
- Update dependencies, and lock them to major releases.
|
56
|
+
- Add a license to the gemspec.
|
57
|
+
- Add a default rake task.
|
58
|
+
|
59
|
+
### v0.0.11 (2014-02-16)
|
60
|
+
|
61
|
+
- [#33](https://github.com/kytrinyx/approvals/pull/33) Append a trailing newline to all approval files. - [@markijbema](https://github.com/markijbema)
|
62
|
+
|
63
|
+
### v0.0.10 (2014-01-30)
|
64
|
+
|
65
|
+
- [#9](https://github.com/kytrinyx/approvals/pull/9) Add option to let RSpec handle diffing when approval fails. - [@jeremyruppel](https://github.com/jeremyruppel)
|
66
|
+
- [#19](https://github.com/kytrinyx/approvals/pull/19) Switch rspec fail_with args so diff is correct. - [@bmarini](https://github.com/bmarini)
|
67
|
+
- Fix build, clean up specs, add badges, add CHANGELOG, fix warnings. - [@markijbema](https://github.com/markijbema)
|
68
|
+
|
69
|
+
### v0.0.9 (2013-10-08)
|
70
|
+
|
71
|
+
Before this version, no changelog was maintained
|
data/Gemfile
ADDED
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2011 Katrina Owen
|
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 NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,263 @@
|
|
1
|
+
# Approvals
|
2
|
+
|
3
|
+
[](http://travis-ci.org/kytrinyx/approvals)
|
4
|
+
[](http://badge.fury.io/rb/approvals)
|
5
|
+
[](https://codeclimate.com/github/kytrinyx/approvals)
|
6
|
+
[](https://gemnasium.com/kytrinyx/approvals)
|
7
|
+
|
8
|
+
|
9
|
+
Approvals are based on the idea of the *_golden master_*.
|
10
|
+
|
11
|
+
You take a snapshot of an object, and then compare all future
|
12
|
+
versions of the object to the snapshot.
|
13
|
+
|
14
|
+
Big hat tip to Llewellyn Falco who developed the approvals concept, as
|
15
|
+
well as the original approvals libraries (.NET, Java, Ruby, PHP,
|
16
|
+
probably others).
|
17
|
+
|
18
|
+
See [ApprovalTests](http://www.approvaltests.com) for videos and additional documentation about the general concept.
|
19
|
+
|
20
|
+
Also, check out Herding Code's [podcast #117](http://t.co/GLn88R5) in
|
21
|
+
which Llewellyn Falco is interviewed about approvals.
|
22
|
+
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Approvals.configure do |config|
|
27
|
+
config.approvals_path = 'output/goes/here/'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
The default location for the output files is
|
32
|
+
|
33
|
+
```plain
|
34
|
+
approvals/
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
Approvals.verify(your_subject, :format => :json)
|
41
|
+
```
|
42
|
+
|
43
|
+
This will raise an `ApprovalError` in the case of a failure.
|
44
|
+
|
45
|
+
The first time the approval is run, a file will be created with the contents of the subject of your approval:
|
46
|
+
|
47
|
+
the_name_of_the_approval.received.txt # or .json, .html, .xml as appropriate
|
48
|
+
|
49
|
+
Since you have not yet approved anything, the `*.approved` file does not exist, and the comparison will fail.
|
50
|
+
|
51
|
+
### Customizing formatted output
|
52
|
+
|
53
|
+
The default writer uses the `:to_s` method on the subject to generate the output for the received file.
|
54
|
+
For custom complex objects you will need to provide a custom writer to get helpful output, rather than the default:
|
55
|
+
|
56
|
+
#<Object:0x0000010105ea40> # or whatever the object id is
|
57
|
+
|
58
|
+
Create a custom writer class somewhere accessible to your test:
|
59
|
+
|
60
|
+
```
|
61
|
+
class MyCustomWriter < Approvals::Writers::TextWriter
|
62
|
+
def format(data)
|
63
|
+
# Custom data formatting here
|
64
|
+
end
|
65
|
+
|
66
|
+
def filter(data)
|
67
|
+
# Custom data filtering here
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
In your test, use a string to reference your custom class:
|
73
|
+
|
74
|
+
```
|
75
|
+
it "verifies a complex object" do
|
76
|
+
Approvals.verify hello, :format => "MyCustomWriter"
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
Define and use different custom writers as needed!
|
81
|
+
|
82
|
+
## CLI
|
83
|
+
|
84
|
+
The gem comes with a command-line tool that makes it easier to manage the
|
85
|
+
`*.received.*` and `*.approved.*` files.
|
86
|
+
|
87
|
+
The basic usage is:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
approvals verify
|
91
|
+
```
|
92
|
+
|
93
|
+
This goes through each approval failure in turn showing you the diff.
|
94
|
+
|
95
|
+
The option `--diff` or `-d` configures which difftool to use (for example
|
96
|
+
`opendiff`, `vimdiff`, etc). The default value is `diff`.
|
97
|
+
|
98
|
+
The option `--ask` or `-a`, which after showing you a diff will offer to
|
99
|
+
approve the received file (move it from `*.received.*` to `*.approved.*`.).
|
100
|
+
The default is `true`. If you set this to `false`, then nothing happens beyond
|
101
|
+
showing you the diff, and you will need to rename files manually.
|
102
|
+
|
103
|
+
### Workflow Using VimDiff
|
104
|
+
|
105
|
+
I have the following mapped to `<leader>v` in my .vimrc file:
|
106
|
+
|
107
|
+
```viml
|
108
|
+
map <leader>v :!approvals verify -d vimdiff -a<cr>
|
109
|
+
```
|
110
|
+
|
111
|
+
I tend to run my tests from within vim with an on-the-fly mapping:
|
112
|
+
|
113
|
+
```viml
|
114
|
+
:map Q :wa <Bar> :!ruby path/to/test_file.rb<cr>
|
115
|
+
```
|
116
|
+
|
117
|
+
When I get one or more approval failures, I hit `<leader>v`. This gives me the
|
118
|
+
vimdiff.
|
119
|
+
|
120
|
+
When I've inspected the result, I hit `:qa` which closes both sides of the
|
121
|
+
diff.
|
122
|
+
|
123
|
+
Then I'm asked if I want to approve the received file `[yN]`. If there are
|
124
|
+
multiple diffs, this handles each failure in turn.
|
125
|
+
|
126
|
+
### RSpec
|
127
|
+
|
128
|
+
For the moment the only direct integration is with RSpec.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
require 'approvals/rspec'
|
132
|
+
```
|
133
|
+
|
134
|
+
The default directory for output files when using RSpec is
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
spec/fixtures/approvals/
|
138
|
+
```
|
139
|
+
|
140
|
+
You can override this:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
RSpec.configure do |config|
|
144
|
+
config.approvals_path = 'some/other/path'
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
The basic format of the approval is modeled after RSpec's `it`:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
it 'works' do
|
152
|
+
verify do
|
153
|
+
'this is the the thing you want to verify'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
### Naming
|
159
|
+
|
160
|
+
When using RSpec, the namer is set for you, using the example's `full_description`.
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
Approvals.verify(thing, :name => 'the name of your test')
|
164
|
+
```
|
165
|
+
|
166
|
+
### Formatting
|
167
|
+
|
168
|
+
You can pass a format for your output before it gets written to the file.
|
169
|
+
At the moment, only text, xml, html, and json are supported, while text is the default.
|
170
|
+
|
171
|
+
Simply add a `:format => :text`, `:format => :xml`, `:format => :html`, or `:format => :json` option to the example:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
page = '<html><head></head><body><h1>ZOMG</h1></body></html>'
|
175
|
+
Approvals.verify page, :format => :html
|
176
|
+
|
177
|
+
data = '{\'beverage\':\'coffee\'}'
|
178
|
+
Approvals.verify data, :format => :json
|
179
|
+
```
|
180
|
+
|
181
|
+
In RSpec, it looks like this:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
verify :format => :html do
|
185
|
+
'<html><head></head><body><h1>ZOMG</h1></body></html>'
|
186
|
+
end
|
187
|
+
|
188
|
+
verify :format => :json do
|
189
|
+
'{\'beverage\':\'coffee\'}'
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
193
|
+
If you like you could also change the default format globally with:
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
RSpec.configure do |config|
|
197
|
+
config.approvals_default_format = :json # or :xml, :html
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
201
|
+
### Exclude dynamically changed values from json
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
Approvals.configure do |config|
|
205
|
+
config.excluded_json_keys = {
|
206
|
+
:id =>/(\A|_)id$/,
|
207
|
+
:date => /_at$/
|
208
|
+
}
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
It will replace values with placeholders:
|
213
|
+
|
214
|
+
{id: 5, created_at: "2013-08-29 13:48:08 -0700"}
|
215
|
+
|
216
|
+
=>
|
217
|
+
|
218
|
+
{id: "<id>", created_at: "<date>"}
|
219
|
+
|
220
|
+
### Approving a spec
|
221
|
+
|
222
|
+
If the contents of the received file is to your liking, you can approve
|
223
|
+
the file by renaming it.
|
224
|
+
|
225
|
+
For an example who's full description is `My Spec`:
|
226
|
+
|
227
|
+
mv my_spec.received.txt my_spec.approved.txt
|
228
|
+
|
229
|
+
When you rerun the approval, it should now pass.
|
230
|
+
|
231
|
+
### Expensive computations
|
232
|
+
|
233
|
+
The Executable class allows you to perform expensive operations only when the command to execute it changes.
|
234
|
+
|
235
|
+
For example, if you have a SQL query that is very slow, you can create an executable with the actual SQL to be performed.
|
236
|
+
|
237
|
+
The first time the spec runs, it will fail, allowing you to inspect the results.
|
238
|
+
If this output looks right, approve the query. The next time the spec is run, it will compare only the actual SQL.
|
239
|
+
|
240
|
+
If someone changes the query, then the comparison will fail. Both the previously approved command and the received command will be executed so that you can inspect the difference between the results of the two.
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
executable = Approvals::Executable.new(subject.slow_sql) do |output|
|
244
|
+
# do something on failure
|
245
|
+
end
|
246
|
+
|
247
|
+
Approvals.verify(executable, :options => :here)
|
248
|
+
```
|
249
|
+
|
250
|
+
### RSpec executable
|
251
|
+
|
252
|
+
There is a convenience wrapper for RSpec that looks like so:
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
verify do
|
256
|
+
executable(subject.slow_sql) do |command|
|
257
|
+
result = ActiveRecord::Base.connection.execute(command)
|
258
|
+
# do something to display the result
|
259
|
+
end
|
260
|
+
end
|
261
|
+
```
|
262
|
+
|
263
|
+
Copyright (c) 2011 Katrina Owen, released under the MIT license
|
data/Rakefile
ADDED
data/approvals.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require 'approvals/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "br-approvals"
|
8
|
+
s.version = Approvals::VERSION
|
9
|
+
s.licenses = ['MIT']
|
10
|
+
s.authors = ["Katrina Owen"]
|
11
|
+
s.email = ["katrina.owen@gmail.com"]
|
12
|
+
s.homepage = ""
|
13
|
+
s.summary = %q{Approval Tests for Ruby}
|
14
|
+
s.description = %q{Approval Tests for Ruby}
|
15
|
+
|
16
|
+
s.rubyforge_project = "approvals"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
s.extensions << 'ext/mkrf_conf.rb'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rspec', '~> 3.1'
|
25
|
+
s.add_dependency 'thor', '~> 0.18'
|
26
|
+
s.add_dependency 'nokogiri', '~> 1.6'
|
27
|
+
# We also depend on the json gem, but the version we need is
|
28
|
+
# Ruby-version-specific. See `ext/mkrf_conf.rb`.
|
29
|
+
end
|