approvals 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -60,19 +60,17 @@ You can override this:
60
60
 
61
61
  The basic format of the approval is modeled after RSpec's `it`:
62
62
 
63
- verify "something" do
64
- "this is the the thing you want to verify"
63
+ it "works" do
64
+ verify do
65
+ "this is the the thing you want to verify"
66
+ end
65
67
  end
66
68
 
67
69
  ### Naming
68
70
 
69
- Currently there is only an RSpecNamer that takes an example (or any object that responds to `:full_description`).
70
-
71
- namer = Approvals::Namers::RSpecNamer.new(example)
72
-
73
- Approvals.verify(thing, :namer => namer, :format => :html)
71
+ When using RSpec, the namer is set for you, using the example's `full_description`.
74
72
 
75
- When using RSpec, the namer is set for you.
73
+ Approvals.verify(thing, :name => "the name of your test")
76
74
 
77
75
  ### Formatting
78
76
 
@@ -81,11 +79,19 @@ At the moment, only xml, html, and json are supported.
81
79
 
82
80
  Simply add a `:format => :xml`, `:format => :html`, or `:format => :json` option to the example:
83
81
 
84
- verify "some html", :format => :html do
82
+ page = "<html><head></head><body><h1>ZOMG</h1></body></html>"
83
+ Approvals.verify page, :format => :html
84
+
85
+ data = "{\"beverage\":\"coffee\"}"
86
+ Approvals.verify data, :format => :html
87
+
88
+ In RSpec, it looks like this:
89
+
90
+ verify :format => :html do
85
91
  "<html><head></head><body><h1>ZOMG</h1></body></html>"
86
92
  end
87
93
 
88
- verify "some json", :format => :json do
94
+ verify :format => :json do
89
95
  "{\"beverage\":\"coffee\"}"
90
96
  end
91
97
 
@@ -112,7 +118,7 @@ If this output looks right, approve the query. The next time the spec is run, it
112
118
  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.
113
119
 
114
120
  executable = Approvals::Executable.new(subject.slow_sql) do |output|
115
- # do something on failure
121
+ # do something on failure
116
122
  end
117
123
 
118
124
  Approvals.verify(executable, :options => :here)
@@ -121,7 +127,7 @@ If someone changes the query, then the comparison will fail. Both the previously
121
127
 
122
128
  There is a convenience wrapper for RSpec that looks like so:
123
129
 
124
- verify "an executable" do
130
+ verify do
125
131
  executable(subject.slow_sql) do |command|
126
132
  result = ActiveRecord::Base.connection.execute(command)
127
133
  # do something to display the result
data/approvals.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "approvals"
6
- s.version = "0.0.3"
6
+ s.version = "0.0.4"
7
7
  s.authors = ["Katrina Owen"]
8
8
  s.email = ["katrina.owen@gmail.com"]
9
9
  s.homepage = ""
@@ -12,7 +12,7 @@ module Approvals
12
12
  end
13
13
 
14
14
  def default_namer(name)
15
- Namers::DefaultNamer.new(name)
15
+ Approvals::Approval.namer || Namers::DefaultNamer.new(name)
16
16
  end
17
17
 
18
18
  def identify_format
@@ -1,11 +1,9 @@
1
1
  if defined? RSpec
2
2
  require 'approvals/extensions/rspec/dsl'
3
- require 'approvals/extensions/rspec/example_group'
4
- require 'approvals/extensions/rspec/example'
5
3
  require 'approvals/namers/rspec_namer'
6
4
 
7
5
  RSpec.configure do |c|
8
- c.extend Approvals::RSpec::DSL
6
+ c.include Approvals::RSpec::DSL
9
7
  c.add_setting :approvals_path, :default => 'spec/fixtures/approvals/'
10
8
  end
11
9
  end
@@ -4,6 +4,12 @@ module Approvals
4
4
  def executable(command, &block)
5
5
  Approvals::Executable.new(command, &block)
6
6
  end
7
+
8
+ def verify(options = {}, &block)
9
+ group = eval "self", block.binding
10
+ namer = Approvals::Namers::RSpecNamer.new(group.example)
11
+ Approvals.verify(block.call, options.merge(:namer => namer))
12
+ end
7
13
  end
8
14
  end
9
15
  end
@@ -2,49 +2,63 @@ require 'approvals'
2
2
  require 'approvals/rspec'
3
3
 
4
4
  describe "Verifies" do
5
- verify "a string" do
6
- "We have, I fear, confused power with greatness."
5
+ specify "a string" do
6
+ verify do
7
+ "We have, I fear, confused power with greatness."
8
+ end
7
9
  end
8
10
 
9
- verify "an array" do
10
- array = [
11
- "abc",
12
- 123,
13
- :zomg_fooooood,
14
- %w(cheese burger ribs steak bacon)
15
- ]
11
+ specify "an array" do
12
+ verify do
13
+ array = [
14
+ "abc",
15
+ 123,
16
+ :zomg_fooooood,
17
+ %w(cheese burger ribs steak bacon)
18
+ ]
19
+ end
16
20
  end
17
21
 
18
- verify "a complex object" do
19
- hello = Object.new
20
- def hello.to_s
21
- "Hello, World!"
22
- end
22
+ specify "a complex object" do
23
+ verify do
24
+ hello = Object.new
25
+ def hello.to_s
26
+ "Hello, World!"
27
+ end
23
28
 
24
- def hello.inspect
25
- "#<The World Says: Hello!>"
26
- end
29
+ def hello.inspect
30
+ "#<The World Says: Hello!>"
31
+ end
27
32
 
28
- hello
33
+ hello
34
+ end
29
35
  end
30
36
 
31
- verify "html", :format => :html do
32
- html = <<-HTML
37
+ specify "html" do
38
+ verify :format => :html do
39
+ html = <<-HTML
33
40
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"><html><head><title>Approval</title></head><body><h1>An Approval</h1><p>It has a paragraph</p></body></html>
34
- HTML
41
+ HTML
42
+ end
35
43
  end
36
44
 
37
- verify "xml", :format => :xml do
38
- xml = "<xml char=\"kiddo\"><node><content name='beatrice' /></node><node aliases='5'><content /></node></xml>"
45
+ specify "xml" do
46
+ verify :format => :xml do
47
+ xml = "<xml char=\"kiddo\"><node><content name='beatrice' /></node><node aliases='5'><content /></node></xml>"
48
+ end
39
49
  end
40
50
 
41
- verify "json", :format => :json do
42
- json = '{"pet":{"species":"turtle","color":"green","name":"Anthony"}}'
51
+ specify "json" do
52
+ verify :format => :json do
53
+ json = '{"pet":{"species":"turtle","color":"green","name":"Anthony"}}'
54
+ end
43
55
  end
44
56
 
45
- verify "an executable" do
46
- executable('SELECT 1') do |command|
47
- puts "your slip is showing (#{command})"
57
+ specify "an executable" do
58
+ verify do
59
+ executable('SELECT 1') do |command|
60
+ puts "your slip is showing (#{command})"
61
+ end
48
62
  end
49
63
  end
50
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: approvals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70111327294940 !ruby/object:Gem::Requirement
16
+ requirement: &70128394108280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.7'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70111327294940
24
+ version_requirements: *70128394108280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &70111327293480 !ruby/object:Gem::Requirement
27
+ requirement: &70128394107880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70111327293480
35
+ version_requirements: *70128394107880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &70111327292400 !ruby/object:Gem::Requirement
38
+ requirement: &70128394107400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70111327292400
46
+ version_requirements: *70128394107400
47
47
  description: Approval Tests for Ruby
48
48
  email:
49
49
  - katrina.owen@gmail.com
@@ -67,8 +67,6 @@ files:
67
67
  - lib/approvals/error.rb
68
68
  - lib/approvals/extensions/rspec.rb
69
69
  - lib/approvals/extensions/rspec/dsl.rb
70
- - lib/approvals/extensions/rspec/example.rb
71
- - lib/approvals/extensions/rspec/example_group.rb
72
70
  - lib/approvals/namers/default_namer.rb
73
71
  - lib/approvals/namers/rspec_namer.rb
74
72
  - lib/approvals/reporters.rb
@@ -1,17 +0,0 @@
1
- module Approvals
2
- module RSpec
3
- class Example < ::RSpec::Core::Example
4
-
5
- attr_reader :received
6
- def initialize(example_group, description, options, &block)
7
- super(example_group, description, options, block)
8
-
9
- namer = Approvals::Namers::RSpecNamer.new(self)
10
- approval = Approval.new(@example_block.call, options.merge(:namer => namer))
11
- @example_block = Proc.new { approval.verify }
12
- end
13
- end
14
- end
15
- end
16
-
17
-
@@ -1,15 +0,0 @@
1
- module Approvals
2
- module RSpec
3
- module ExampleGroup
4
-
5
- def verify(desc=nil, *args, &block)
6
- options = build_metadata_hash_from(args)
7
- examples << Approvals::RSpec::Example.new(self, desc, options, &block)
8
- examples.last
9
- end
10
-
11
- end
12
- end
13
- end
14
-
15
- RSpec::Core::ExampleGroup.send(:extend, Approvals::RSpec::ExampleGroup)