approval_tests 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +29 -0
  4. data/README +1 -0
  5. data/Rakefile +8 -4
  6. data/approval_tests.gemspec +10 -49
  7. data/cucumber.yml +1 -0
  8. data/{spec/spec.opts → features/.approved.txt} +0 -0
  9. data/features/.received.txt +1 -0
  10. data/features/basic_approval.approves_string.approved.txt +1 -0
  11. data/features/basic_approval.feature +13 -0
  12. data/features/basic_approval_approves_string.approved.txt +1 -0
  13. data/features/step_definitions/basic_steps.rb +17 -0
  14. data/features/support/env.rb +9 -0
  15. data/features/support/paths.rb +98 -0
  16. data/lib/approval_tests.rb +20 -2
  17. data/lib/approval_tests/approvals.rb +39 -39
  18. data/lib/approval_tests/approvers.rb +1 -0
  19. data/lib/approval_tests/approvers/file_approver.rb +3 -3
  20. data/lib/approval_tests/extensions/cucumber.rb +7 -0
  21. data/lib/approval_tests/extensions/rspec.rb +9 -10
  22. data/lib/approval_tests/namers.rb +1 -0
  23. data/lib/approval_tests/namers/cucumber_namer.rb +29 -0
  24. data/lib/approval_tests/namers/rspec_namer.rb +2 -7
  25. data/lib/approval_tests/reporters.rb +1 -0
  26. data/{spec → lib/approval_tests/reporters}/cleanup_reporter.rb +0 -0
  27. data/lib/approval_tests/reporters/diff_reporter.rb +21 -5
  28. data/lib/approval_tests/reporters/file_launcher_reporter.rb +14 -0
  29. data/lib/approval_tests/reporters/opendiff_reporter.rb +13 -0
  30. data/lib/approval_tests/reporters/quiet_reporter.rb +1 -1
  31. data/lib/approval_tests/reporters/rspec_reporter.rb +17 -0
  32. data/lib/approval_tests/reporters/text_mate_reporter.rb +1 -1
  33. data/lib/approval_tests/reporters/tortoisediff_reporter.rb +15 -0
  34. data/lib/approval_tests/reporters/vimdiff_reporter.rb +13 -0
  35. data/lib/approval_tests/utils.rb +7 -0
  36. data/lib/approval_tests/writers.rb +1 -0
  37. data/lib/approval_tests/writers/html_writer.rb +3 -1
  38. data/spec/{a.txt → approval_tests/a.txt} +0 -0
  39. data/spec/{approvals_should_approve_shared_behaviors.approved.txt → approval_tests/approvals_it_should_behave_like_shared_behaviors_should_approve_shared_behaviors.approved.txt} +0 -0
  40. data/spec/{approvals_lists_should_show_empty_lists.approved.txt → approval_tests/approvals_lists_should_show_empty_lists.approved.txt} +0 -0
  41. data/spec/approval_tests/approvals_lists_should_write_arrays.approved.txt +3 -0
  42. data/spec/approval_tests/approvals_lists_should_write_maps.approved.txt +1 -0
  43. data/spec/{approvals_multiple_describes_should_approve_multiple_describes.approved.txt → approval_tests/approvals_multiple_describes_should_approve_multiple_describes.approved.txt} +0 -0
  44. data/spec/approval_tests/approvals_should_approve_shared_behaviors.approved.txt +1 -0
  45. data/spec/{approvals_should_successfully_approve_text.approved.txt → approval_tests/approvals_should_successfully_approve_text.approved.txt} +0 -0
  46. data/spec/{approvals_spec.rb → approval_tests/approvals_spec.rb} +18 -22
  47. data/spec/{approvals_using_approval_blocks.approved.txt → approval_tests/approvals_using_approval_blocks.approved.txt} +0 -0
  48. data/spec/{approvals_using_approval_blocks_the_last_statement.approved.txt → approval_tests/approvals_using_approval_blocks_the_last_statement.approved.txt} +0 -0
  49. data/spec/{approvals_xml_should_be_pretty.approved.txt → approval_tests/approvals_xml_should_be_pretty.approved.txt} +0 -0
  50. data/spec/{b.txt → approval_tests/b.txt} +0 -0
  51. data/spec/approval_tests/reporter_spec.rb +55 -0
  52. data/spec/approval_tests/self_example_group_full_description.received.txt +1 -0
  53. data/spec/approval_tests/system_spec.rb +11 -0
  54. data/spec/spec_helper.rb +4 -13
  55. metadata +64 -49
  56. data/spec/approvals_lists_should_write_arrays.approved.txt +0 -1
  57. data/spec/approvals_lists_should_write_maps.approved.txt +0 -1
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWY3NTQ1YWVlYWFlZWYwNzc3NzQ2Y2RjNjI2MjAzZTA2ZmYyMTUxMg==
5
+ data.tar.gz: !binary |-
6
+ MDhjN2I2OWM5MTI5YjRiYmM3MmQ2ZjEzMmRjNWE0MWU0Mjc4NzFmMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ODZiMjZkNTIxYzk2YzI4MDBmMDQ3NzJhNmJkNTcxZDY2M2FiMmNiZDIzMThh
10
+ ZjU5YjkwOTI5NzcwYjA4MDVmOWYxYzZiMWU2MmFkMzY2NjFlYmQ3MTI4YjI5
11
+ YmEwZWMyMzY2MjVhNDQwZDEyMWM5MWRjNzQyZmY2ODIyZmUxZGE=
12
+ data.tar.gz: !binary |-
13
+ MWE4ODY0NzZjMWEzNzEzOGUyYjU2MTQ0NWM0MGE1ZDRiMDM1Y2JlMjAwMWM3
14
+ MGQ4ZTNlNjMxMzZjYjlkOTg3M2FiYTlkYTRhYmE4NTk5NmI5NThlZjkwN2My
15
+ OWI0MWIwODNhMTlhZmI1MDkzN2RjMDZjMWQ3MTQ1ZjQ0ZTFhNTQ=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ group :development, :test do
2
+ gem 'rspec'
3
+ gem 'cucumber'
4
+ end
@@ -0,0 +1,29 @@
1
+ GEM
2
+ specs:
3
+ builder (2.1.2)
4
+ cucumber (1.0.2)
5
+ builder (>= 2.1.2)
6
+ diff-lcs (>= 1.1.2)
7
+ gherkin (~> 2.4.5)
8
+ json (>= 1.4.6)
9
+ term-ansicolor (>= 1.0.5)
10
+ diff-lcs (1.1.2)
11
+ gherkin (2.4.6)
12
+ json (>= 1.4.6)
13
+ json (1.5.3)
14
+ rspec (2.6.0)
15
+ rspec-core (~> 2.6.0)
16
+ rspec-expectations (~> 2.6.0)
17
+ rspec-mocks (~> 2.6.0)
18
+ rspec-core (2.6.4)
19
+ rspec-expectations (2.6.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.6.0)
22
+ term-ansicolor (1.0.6)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ cucumber
29
+ rspec
data/README CHANGED
@@ -0,0 +1 @@
1
+ Check out www.approvaltests.com for instructions
data/Rakefile CHANGED
@@ -1,11 +1,15 @@
1
1
  require 'rubygems'
2
- require 'spec/rake/spectask'
2
+ require 'rspec/core/rake_task'
3
+ require 'cucumber/rake/task'
3
4
 
4
- Spec::Rake::SpecTask.new('specs') do |t|
5
- t.spec_opts = ["--format", "specdoc", "--colour"]
6
- t.spec_files = Dir['spec/**/*_spec.rb'].sort
5
+ task :default => ["specs", "features"]
6
+
7
+ RSpec::Core::RakeTask.new('specs') do |t|
8
+ t.rspec_opts = ["--format", "documentation", "--colour"]
7
9
  end
8
10
 
11
+ Cucumber::Rake::Task.new('features')
12
+
9
13
  begin
10
14
  require 'jeweler'
11
15
  Jeweler::Tasks.new do |gemspec|
@@ -1,68 +1,29 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = %q{approval_tests}
5
- s.version = "0.0.8"
6
+ s.version = "0.0.9"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.rubygems_version = %q{1.3.4}
8
10
  s.authors = ["Dan Gilkerson, Llewellyn Falco"]
9
11
  s.date = %q{2009-07-03}
10
12
  s.description = %q{Approval testing library for ruby}
11
13
  s.email = %q{approvaltests@dangilkerson.com}
12
- s.extra_rdoc_files = [
13
- "README"
14
- ]
15
- s.files = [
16
- "README",
17
- "Rakefile",
18
- "VERSION",
19
- "approval_tests.gemspec",
20
- "lib/approval_tests.rb",
21
- "lib/approval_tests/approvals.rb",
22
- "lib/approval_tests/approvers/file_approver.rb",
23
- "lib/approval_tests/extensions/rspec.rb",
24
- "lib/approval_tests/namers/rspec_namer.rb",
25
- "lib/approval_tests/reporters/diff_reporter.rb",
26
- "lib/approval_tests/reporters/quiet_reporter.rb",
27
- "lib/approval_tests/reporters/text_mate_reporter.rb",
28
- "lib/approval_tests/writers/html_writer.rb",
29
- "lib/approval_tests/writers/text_writer.rb",
30
- "lib/approval_tests/writers/xml_writer.rb",
31
- "spec/a.txt",
32
- "spec/approvals_lists_should_show_empty_lists.approved.txt",
33
- "spec/approvals_lists_should_write_arrays.approved.txt",
34
- "spec/approvals_lists_should_write_maps.approved.txt",
35
- "spec/approvals_multiple_describes_should_approve_multiple_describes.approved.txt",
36
- "spec/approvals_should_approve_shared_behaviors.approved.txt",
37
- "spec/approvals_should_successfully_approve_text.approved.txt",
38
- "spec/approvals_spec.rb",
39
- "spec/approvals_using_approval_blocks.approved.txt",
40
- "spec/approvals_using_approval_blocks_the_last_statement.approved.txt",
41
- "spec/approvals_xml_should_be_pretty.approved.txt",
42
- "spec/b.txt",
43
- "spec/cleanup_reporter.rb",
44
- "spec/spec.opts",
45
- "spec/spec_helper.rb"
46
- ]
47
- s.homepage = %q{http://github.com/approvaltests/approval_tests}
14
+ s.extra_rdoc_files = ["README"]
15
+ s.homepage = %q{http://github.com/approvals/approval_tests}
48
16
  s.rdoc_options = ["--charset=UTF-8"]
49
- s.require_paths = ["lib"]
50
17
  s.rubyforge_project = %q{approvaltests}
51
- s.rubygems_version = %q{1.3.4}
52
18
  s.summary = %q{Approval testing library}
53
- s.test_files = [
54
- "spec/approvals_spec.rb",
55
- "spec/cleanup_reporter.rb",
56
- "spec/spec_helper.rb"
57
- ]
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
58
24
 
59
25
  if s.respond_to? :specification_version then
60
26
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
61
27
  s.specification_version = 3
62
-
63
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
64
- else
65
- end
66
- else
67
28
  end
68
29
  end
@@ -0,0 +1 @@
1
+ default: features
@@ -0,0 +1 @@
1
+ Hello World
@@ -0,0 +1,13 @@
1
+ Feature: Basic Approval
2
+ As a testing person
3
+ I want to be able to use the basics of Approvals
4
+
5
+ Scenario: Approves String
6
+ Given a string "Hello World"
7
+ Then verify the string
8
+
9
+ Scenario: Approval names
10
+ Then the approval name is "basic_approval_approval_names"
11
+
12
+ Scenario: Understand paths
13
+ Then the path contains "basic_approval.feature"
@@ -0,0 +1,17 @@
1
+ Given /^a string "([^\"]*)"$/ do |str|
2
+ @string = str
3
+ end
4
+
5
+ Then /^verify the string$/ do
6
+ Approvals.reporter(Reporters::OpendiffReporter.new)
7
+ Approvals.approve(@string)
8
+ end
9
+
10
+ Then /^the approval name is "([^"]*)"$/ do |name|
11
+ Approvals.namer.approval_name.should == name
12
+ end
13
+
14
+ Then /^the path contains "([^"]*)"$/ do |file|
15
+ feature_file_with_path = Approvals.namer.source_file_path + "/" + file
16
+ File.exists?(feature_file_with_path).should be_true
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'cucumber/formatter/unicode'
2
+
3
+ __DIR__ = File.join(File.dirname(__FILE__) + '/../../lib')
4
+ $LOAD_PATH.unshift __DIR__ unless
5
+ $LOAD_PATH.include?(__DIR__) ||
6
+ $LOAD_PATH.include?(File.expand_path(__DIR__))
7
+
8
+ require 'approval_tests'
9
+ require 'approval_tests/extensions/cucumber'
@@ -0,0 +1,98 @@
1
+ module NavigationHelpers
2
+ # Maps a static name to a static route.
3
+ #
4
+ # This method is *not* designed to map from a dynamic name to a
5
+ # dynamic route like <tt>post_comments_path(post)</tt>. For dynamic
6
+ # routes like this you should *not* rely on #path_to, but write
7
+ # your own step definitions instead. Example:
8
+ #
9
+ # Given /I am on the comments page for the "(.+)" post/ |name|
10
+ # post = Post.find_by_name(name)
11
+ # visit post_comments_path(post)
12
+ # end
13
+ #
14
+ def path_to(page_name)
15
+ case page_name
16
+
17
+ when /the homepage/
18
+ root_path
19
+ when /the signup page/
20
+ signup_path
21
+ when /the upgrade page/
22
+ upgrade_path
23
+ when /the credentials page/
24
+ credentials_path
25
+ when /the account page/
26
+ account_path
27
+ when /the (login|sign in) page/
28
+ login_path
29
+ when /my bedroom page/
30
+ bedroom_path(@current_user.person)
31
+ when /the bedroom page "([^\"]*)"/
32
+ bedroom_path($1)
33
+ when /the scene named "([^\"]*)"/
34
+ scene = Scene.find_by_title($1)
35
+ scene_path(scene)
36
+ when /the DHD signup page for "([^\"]*)"/
37
+ optionid = MembershipPackage.find_by_name($1).nats_product_id
38
+ username = @current_user.pending_upgrade.username
39
+ email = CGI.escape(@current_user.email)
40
+ password = @current_user.pending_upgrade.password
41
+
42
+ # build it by hand so we're actually checking everything
43
+ normalize_uri(
44
+ "http://enterbedrooms.naughtyamerica.com/signup/signup.php?" +
45
+ "cascade=credit" +
46
+ "&amp;nats=MTAwNDo0OjQx" +
47
+ "&amp;nextra%5BDHD%5D%5BDisableUser_Pass%5D=1" +
48
+ "&amp;nextra%5BDHD%5D%5Bsub_username%5D=#{username}" +
49
+ "&amp;nextra%5BDHD%5D%5BEmail_IsUsername%5D=0" +
50
+ "&amp;nextra%5BDHD%5D%5BWebSiteName%5D=Bedrooms" +
51
+ "&amp;nextra%5BDHD%5D%5BWebsiteHomepage%5D=http%3A%2F%2Fbedrooms.naughtyamerica.com%2F" +
52
+ "&amp;signup%5Bemail%5D=#{email}" +
53
+ "&amp;signup%5Boptionid%5D=#{optionid}" +
54
+ "&amp;signup%5Bpassword%5D=#{password}" +
55
+ "&amp;site=41" +
56
+ "&amp;step=2"
57
+ )
58
+ when /the "keycard" promotion page/
59
+ keycard_path
60
+ when /the candidate signup page/
61
+ signup_candidate_path
62
+ when /the new candidate page/
63
+ new_candidate_path
64
+ when /the candidate page for "([^\"]*)"/
65
+ "/candidates/#{$1}"
66
+ when /the naughty president update candidate page for "([^\"]*)"/
67
+ normalize_uri("http://www.naughtypresident.com/update/#{$1}")
68
+ when /the naughty president candidate page for "([^\"]*)"/
69
+ normalize_uri("http://www.naughtypresident.com/#{$1}")
70
+
71
+ else
72
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
73
+ "Now, go and add a mapping in features/support/paths.rb"
74
+ end
75
+ end
76
+
77
+ def normalize_uri(uri)
78
+ normalized_uri =
79
+ case uri
80
+ when URI then uri
81
+ else
82
+ uri = 'http://' + uri unless uri =~ %r|^https?://|
83
+ URI.parse(uri)
84
+ end
85
+ normalized_uri.query = sort_query_params(normalized_uri.query)
86
+ normalized_uri.normalize
87
+ end
88
+
89
+ def sort_query_params(query)
90
+ if query.nil? || query.empty?
91
+ nil
92
+ else
93
+ query.split('&').sort.join('&')
94
+ end
95
+ end
96
+ end
97
+
98
+ World(NavigationHelpers)
@@ -4,7 +4,25 @@ $LOAD_PATH.unshift __DIR__ unless
4
4
  $LOAD_PATH.include?(__DIR__) ||
5
5
  $LOAD_PATH.include?(File.expand_path(__DIR__))
6
6
 
7
- require "approval_tests/approvals"
8
7
  require "approval_tests/extensions/rspec"
9
8
 
10
- include ApprovalTests::Namers
9
+ require "approval_tests/utils"
10
+ require "approval_tests/namers"
11
+ require "approval_tests/approvers/file_approver"
12
+
13
+ require "approval_tests/writers"
14
+ require "approval_tests/reporters"
15
+
16
+ require "approval_tests/approvals"
17
+
18
+ include ApprovalTests::Approvers
19
+ include ApprovalTests::Writers
20
+ include ApprovalTests::Reporters
21
+ include ApprovalTests::Namers
22
+
23
+ module ApprovalTests
24
+ class ApprovalError < Exception
25
+ attr_accessor :received_filename
26
+ attr_accessor :approved_filename
27
+ end
28
+ end
@@ -1,42 +1,32 @@
1
1
  require 'fileutils'
2
- __DIR__ = File.dirname(__FILE__)
3
- require "#{__DIR__}/namers/rspec_namer"
4
- require "#{__DIR__}/approvers/file_approver"
5
- require "#{__DIR__}/writers/text_writer"
6
- require "#{__DIR__}/writers/html_writer"
7
- require "#{__DIR__}/writers/xml_writer"
8
- require "#{__DIR__}/reporters/quiet_reporter"
9
- require "#{__DIR__}/reporters/text_mate_reporter"
10
- require "#{__DIR__}/reporters/diff_reporter"
11
2
 
12
- include ApprovalTests::Approvers
13
- include ApprovalTests::Writers
14
- include ApprovalTests::Reporters
15
-
16
- module ApprovalTests
17
- class ApprovalError < Exception
18
- attr_accessor :received_filename
19
- attr_accessor :approved_filename
20
- end
3
+ module ApprovalTests
21
4
  class Approvals
22
5
  class << self
6
+ attr_accessor :namer
7
+
23
8
  def approve_list(label, list)
24
-
25
- i = -1;
26
- format = list.map do |m|
27
- i = i+1
28
- "#{label}[#{i}] = #{m} \r"
9
+ format = if list.empty?
10
+ "#{label}.count = 0"
11
+ else
12
+ index = -1
13
+ list.reduce("") do |format, list_element|
14
+ index += 1
15
+ format + "#{label}[#{index}] = #{list_element} \n"
16
+ end
29
17
  end
30
- format = "#{label}.count = 0" if list.empty?
31
- approve(format.to_s)
18
+
19
+ approve(format)
32
20
  end
21
+
33
22
  def approve_map(map)
34
23
  out = "";
35
- map.each do |key,value|
36
- out += "[#{key}] = #{value} \r"
24
+ map.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key|
25
+ out += "[#{key}] = #{map[key]} \r"
37
26
  end
38
27
  approve(out)
39
28
  end
29
+
40
30
  def approve(data)
41
31
  approve_with_writer(TextWriter.new(data))
42
32
  end
@@ -65,17 +55,15 @@ module ApprovalTests
65
55
  end
66
56
  end
67
57
 
68
- def namer=(namer)
69
- @namer = namer
70
- end
71
-
72
- def namer
73
- @namer
74
- end
75
-
76
58
  def get_default_reporter()
77
59
  @reporters ||= []
78
- return @reporters.first() unless @reporters.empty?
60
+ unless @reporters.empty?
61
+ if @single_use
62
+ @single_use = false
63
+ return @reporters.pop
64
+ end
65
+ return @reporters.last
66
+ end
79
67
  if defined? Spec::Mate
80
68
  TextMateReporter.instance
81
69
  else
@@ -84,12 +72,24 @@ module ApprovalTests
84
72
  end
85
73
 
86
74
  def reporter(reporter)
75
+ prepare_reporters
76
+ @reporters.push(reporter)
77
+ end
78
+
79
+ def prepare_reporters
87
80
  @reporters ||= []
88
- @reporters.push(reporter);
81
+ @reporters.pop if @single_use
82
+ @single_use = false
83
+ end
84
+
85
+ def single_use_reporter(reporter)
86
+ prepare_reporters
87
+ @reporters.push(reporter)
88
+ @single_use = true
89
89
  end
90
90
 
91
91
  def unregister_reporter(reporter)
92
- @reporters.remove(reporter);
92
+ @reporters.remove(reporter)
93
93
  end
94
94
 
95
95
  def unregister_last_reporter()
@@ -97,4 +97,4 @@ module ApprovalTests
97
97
  end
98
98
  end
99
99
  end
100
- end
100
+ end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + '/approvers/*_approver.rb'].each {|approver| require approver}
@@ -8,7 +8,7 @@ module ApprovalTests
8
8
  @namer = namer
9
9
  end
10
10
 
11
- def approve()
11
+ def approve
12
12
  basename = "#{@namer.source_file_path}/#{@namer.approval_name}"
13
13
  @approved = @writer.get_approval_filename(basename)
14
14
  @received = @writer.get_received_filename(basename)
@@ -31,7 +31,7 @@ module ApprovalTests
31
31
  return true
32
32
  end
33
33
 
34
- def fail()
34
+ def fail
35
35
  raise @failure
36
36
  end
37
37
 
@@ -39,7 +39,7 @@ module ApprovalTests
39
39
  reporter.report(@approved, @received);
40
40
  end
41
41
 
42
- def clean_up_after_success()
42
+ def clean_up_after_success
43
43
  File.delete(@received)
44
44
  end
45
45
  end
@@ -0,0 +1,7 @@
1
+ Before do |scenario|
2
+ CucumberNamer.create_namer(scenario)
3
+ end
4
+
5
+ World do
6
+ include ApprovalTests
7
+ end
@@ -1,5 +1,3 @@
1
- require "#{File.dirname(__FILE__)}/../approvals"
2
-
3
1
  module ApprovalTests
4
2
  module Extensions
5
3
  module RSpec
@@ -38,13 +36,14 @@ module ApprovalTests
38
36
  end
39
37
  end
40
38
 
41
- Spec::Runner.configure do |config|
42
- config.before(:each) do
43
- Approvals.namer = RSpecNamer.new()
44
- extra_description = ""
45
- extra_description = "_#{self.description}" if !self.description.empty?
46
- Approvals.namer.approval_name = "#{self.class.description}#{extra_description}".gsub("/", "__FORWARD_SLASH__");
47
- Approvals.namer.source_file_path = File.dirname(self.class.location)
39
+ begin
40
+ RSpec.configure do |config|
41
+ config.before(:each) do
42
+ Approvals.namer = RSpecNamer.new()
43
+ Approvals.namer.approval_name = self.example.metadata[:full_description].gsub("/", "__FORWARD_SLASH__");
44
+ Approvals.namer.source_file_path = File.dirname(self.class.metadata[:example_group].location)
45
+ end
46
+ config.extend(ApprovalTests::Extensions::RSpec)
48
47
  end
49
- config.extend(ApprovalTests::Extensions::RSpec)
48
+ rescue NoMethodError
50
49
  end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + '/namers/*_namer.rb'].each {|namer| require namer}
@@ -0,0 +1,29 @@
1
+ module ApprovalTests
2
+ module Namers
3
+ class CucumberNamer
4
+ attr_reader :approval_name
5
+ attr_reader :source_file_path
6
+
7
+ def self.create_namer(scenario)
8
+ feature_file_and_path = scenario.instance_variable_get(:@feature).file
9
+ scenario_name = scenario.name
10
+
11
+ Approvals.namer = CucumberNamer.new(feature_file_and_path, scenario_name)
12
+ end
13
+
14
+ def initialize(feature_file_and_path, scenario_name)
15
+ feature_file_and_path =~ /([^\/]*)\.feature$/
16
+ feature_name = $1
17
+
18
+ @source_file_path = File.dirname(File.expand_path(feature_file_and_path))
19
+
20
+ @approval_name = format("#{feature_name}_#{scenario_name}")
21
+ end
22
+
23
+ def format(string)
24
+ string.downcase.gsub(/ |\./, "_")
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -1,10 +1,8 @@
1
1
  module ApprovalTests
2
2
  module Namers
3
3
  class RSpecNamer
4
-
5
- def approval_name
6
- @approval_name
7
- end
4
+ attr_reader :approval_name
5
+ attr_writer :source_file_path
8
6
 
9
7
  def approval_name=(name)
10
8
  @approval_name = name.downcase.gsub(/ |\./, "_")
@@ -14,9 +12,6 @@ module ApprovalTests
14
12
  @source_file_path ||= File.dirname(File.expand_path(@approval_name))
15
13
  end
16
14
 
17
- def source_file_path=(path)
18
- @source_file_path = path
19
- end
20
15
  end
21
16
  end
22
17
  end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + '/reporters/*_reporter.rb'].each {|reporter| require reporter}
@@ -3,16 +3,32 @@ require 'singleton'
3
3
  module ApprovalTests
4
4
  module Reporters
5
5
  class DiffReporter
6
- include Singleton
6
+ def initialize(&block)
7
+ @launcher = block || self.class.default_launcher
8
+ end
7
9
 
8
10
  def report(approved, received)
9
- TextWriter.write_file(approved,"") unless File.exists?(approved)
10
- exec "/Applications/DiffMerge.app/Contents/MacOS/DiffMerge --nosplash \"#{received}\" \"#{approved}\""
11
+ TextWriter.write_file(approved,"") unless File.exists?(approved)
12
+ QuietReporter.instance.report(approved, received)
13
+ launch(approved, received)
11
14
  end
12
15
 
13
- def approved_when_reported()
16
+ def approved_when_reported
14
17
  false
15
18
  end
19
+
20
+ protected
21
+
22
+ def launch(approved, received)
23
+ exec @launcher.call(approved, received)
24
+ end
25
+
26
+ def self.default_launcher
27
+ lambda { |app, rec|
28
+ "/Applications/DiffMerge.app/Contents/MacOS/DiffMerge --nosplash \"#{rec}\" \"#{app}\""
29
+ }
30
+ end
31
+
16
32
  end
17
33
  end
18
- end
34
+ end
@@ -0,0 +1,14 @@
1
+
2
+ require 'singleton'
3
+
4
+ module ApprovalTests
5
+ module Reporters
6
+ class FileLauncherReporter < DiffReporter
7
+ def self.default_launcher
8
+ lambda { |app, rec|
9
+ "open #{rec}"
10
+ }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'singleton'
2
+
3
+ module ApprovalTests
4
+ module Reporters
5
+ class OpendiffReporter < DiffReporter
6
+ def self.default_launcher
7
+ lambda { |app, rec|
8
+ system("opendiff #{rec} #{app}")
9
+ }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,7 +13,7 @@ module ApprovalTests
13
13
  end
14
14
  end
15
15
 
16
- def approved_when_reported()
16
+ def approved_when_reported
17
17
  false
18
18
  end
19
19
  end
@@ -0,0 +1,17 @@
1
+ require 'singleton'
2
+
3
+ module ApprovalTests
4
+ module Reporters
5
+ class RspecReporter
6
+ include Singleton
7
+
8
+ def report(app, rec)
9
+ approved = ""
10
+ approved = File.read(app) if File.exists?(app)
11
+ received = File.read(rec)
12
+ received.should == approved
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -16,7 +16,7 @@ module ApprovalTests
16
16
  puts "<p></p><iframe src='tm-file://#{File.expand_path(received)}' width='100%' frameborder='0' style='border:solid 1px red'></iframe>"
17
17
  end
18
18
 
19
- def approved_when_reported()
19
+ def approved_when_reported
20
20
  false
21
21
  end
22
22
  end
@@ -0,0 +1,15 @@
1
+ require 'singleton'
2
+
3
+ module ApprovalTests
4
+ module Reporters
5
+ class TortoisediffReporter < DiffReporter
6
+ TORTOISE_BIN = 'C:\\Program Files\\TortoiseSVN\\bin\\TortoiseMerge.exe'
7
+
8
+ def self.default_launcher
9
+ lambda { |app, rec|
10
+ system("#{TORTOISE_BIN} #{rec} #{app}")
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require 'singleton'
2
+
3
+ module ApprovalTests
4
+ module Reporters
5
+ class VimdiffReporter < DiffReporter
6
+ def self.default_launcher
7
+ lambda { |app, rec|
8
+ "echo '#!/bin/sh' > /tmp/reporter.command; echo 'vimdiff #{rec} #{app}' > /tmp/reporter.command; chmod +x /tmp/reporter.command; open /tmp/reporter.command"
9
+ }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module ApprovalTests
2
+ module Utils
3
+ def self.program_exists(name)
4
+ system("which #{name}")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + '/writers/*_writer.rb'].each {|writer| require writer}
@@ -17,8 +17,10 @@ module ApprovalTests
17
17
  f = File.new("#{received}", "w+")
18
18
  f.write(@data)
19
19
  f.close()
20
+ system("xmllint --format --html --output #{f.path} #{f.path}") if Utils.program_exists('xmllint')
20
21
  f.path
21
22
  end
23
+
22
24
  end
23
25
  end
24
- end
26
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ name[0] = tom
2
+ name[1] = dick
3
+ name[2] = harry
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "spec_helper")
1
+ require "spec_helper"
2
2
 
3
3
  shared_examples_for "Shared Behaviors" do
4
4
  it "should approve shared behaviors" do
@@ -10,29 +10,29 @@ describe "Approvals" do
10
10
  after(:each) do
11
11
  Approvals.unregister_last_reporter()
12
12
  end
13
-
13
+
14
14
  it_should_behave_like "Shared Behaviors"
15
-
15
+
16
16
  it "should successfully approve text" do
17
17
  Approvals.approve("should be approved")
18
18
  end
19
-
19
+
20
20
  it "should raise mismatch error if received does not match approved" do
21
21
  Approvals.reporter(CleanupReporter.new);
22
22
  lambda { Approvals.approve("should fail with mismatch") }.should raise_error(ApprovalError)
23
23
  end
24
-
24
+
25
25
  it "should raise missing approval error if has not been approved yet" do
26
26
  Approvals.reporter(CleanupReporter.new);
27
27
  lambda { Approvals.approve("should fail with a missing ") }.should raise_error(ApprovalError)
28
28
  end
29
-
29
+
30
30
  describe "Multiple describes" do
31
31
  it "should approve multiple describes" do
32
32
  Approvals.approve("multiple describes")
33
33
  end
34
34
  end
35
-
35
+
36
36
  describe "lists" do
37
37
  it "should write arrays" do
38
38
  Approvals.approve_list("name",["tom","dick","harry"])
@@ -44,32 +44,28 @@ describe "Approvals" do
44
44
  Approvals.approve_map(:name=> "harry", :age => 25, :sex => "male")
45
45
  end
46
46
  end
47
-
47
+
48
48
  describe "xml" do
49
49
  it "should be pretty" do
50
50
  Approvals.approve_xml('<?xml version="1.0" encoding="ISO-8859-1"?><data><a><b>Bee</b><c>Sea</c></a></data>')
51
51
  end
52
52
  end
53
-
53
+
54
54
  describe "DiffReporter" do
55
55
  it "should launch" do
56
- base = "approval_tests/spec/"
57
- # DiffReporter.instance.report("approval_tests/spec/a.txt", "approval_tests/spec/b.txt")
58
- end
59
- it "should create and launch" do
60
- base = "approval_tests/spec/"
61
- File.delete("#{base}c.txt") if File.exists?("#{base}c.txt")
62
- # DiffReporter.instance.report("#{base}c.txt", "#{base}a.txt")
63
- end
56
+ base = "approval_tests/spec/approval_tests"
57
+ # DiffReporter.instance.report("approval_tests/spec/a.txt", "approval_tests/spec/b.txt")
58
+ end
59
+ it "should create and launch" do
60
+ base = "approval_tests/spec/approval_tests"
61
+ File.delete("#{base}c.txt") if File.exists?("#{base}c.txt")
62
+ # DiffReporter.instance.report("#{base}c.txt", "#{base}a.txt")
63
+ end
64
64
  end
65
-
66
65
  end
67
66
 
68
-
69
-
70
67
  describe "Approvals", "using approval blocks" do
71
68
  approve "the last statement" do
72
69
  "approve this"
73
70
  end
74
-
75
- end
71
+ end
File without changes
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Reporters" do
4
+ it "calls the reporters in order" do
5
+ r1 = DiffReporter.new
6
+ r2 = DiffReporter.new
7
+
8
+ Approvals.reporter(r1)
9
+ Approvals.get_default_reporter.should == r1
10
+
11
+ Approvals.reporter(r2)
12
+ Approvals.get_default_reporter.should == r2
13
+
14
+ Approvals.unregister_last_reporter
15
+ Approvals.get_default_reporter.should == r1
16
+ end
17
+
18
+ it "one-use reporters" do
19
+ r1 = DiffReporter.new
20
+ r2 = DiffReporter.new
21
+
22
+ Approvals.reporter(r1)
23
+ Approvals.get_default_reporter.should == r1
24
+
25
+ Approvals.single_use_reporter(r2)
26
+ Approvals.get_default_reporter.should == r2
27
+
28
+ Approvals.get_default_reporter.should == r1
29
+ end
30
+
31
+ it "indecisive single use" do
32
+ r1 = DiffReporter.new
33
+ Approvals.single_use_reporter(r1)
34
+ Approvals.unregister_last_reporter
35
+ Approvals.single_use_reporter(r1)
36
+ Approvals.get_default_reporter.should_not be_nil
37
+ end
38
+
39
+ it "one-use reporter, expiration" do
40
+ r1 = DiffReporter.new
41
+ r2 = DiffReporter.new
42
+ r3 = DiffReporter.new
43
+
44
+ Approvals.reporter(r1)
45
+ Approvals.get_default_reporter.should == r1
46
+
47
+ Approvals.single_use_reporter(r2)
48
+ Approvals.single_use_reporter(r3)
49
+
50
+ Approvals.get_default_reporter.should == r3
51
+
52
+ Approvals.get_default_reporter.should == r1
53
+ end
54
+
55
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe '#program_exists' do
4
+ it "should recognize a command that exists" do
5
+ ApprovalTests::Utils.program_exists('ls').should be_true
6
+ end
7
+
8
+ it "should not recognize weird commands" do
9
+ ApprovalTests::Utils.program_exists('weirdo-commando').should be_false
10
+ end
11
+ end
@@ -1,18 +1,9 @@
1
1
  require 'rubygems'
2
- require 'spec'
3
-
4
- __DIR__ = File.join(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift __DIR__ unless
6
- $LOAD_PATH.include?(__DIR__) ||
7
- $LOAD_PATH.include?(File.expand_path(__DIR__))
8
-
9
- require 'cleanup_reporter'
10
-
11
- __DIR__ = File.join(__DIR__, "..", "lib")
2
+ require 'rspec'
12
3
 
13
- $LOAD_PATH.unshift __DIR__ unless
14
- $LOAD_PATH.include?(__DIR__) ||
15
- $LOAD_PATH.include?(File.expand_path(__DIR__))
4
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
5
+ $:.unshift(File.dirname(__FILE__))
16
6
 
17
7
  require 'approval_tests'
8
+
18
9
  include ApprovalTests
metadata CHANGED
@@ -1,86 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: approval_tests
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Dan Gilkerson, Llewellyn Falco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-07-03 00:00:00 -07:00
13
- default_executable:
11
+ date: 2009-07-03 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
13
  description: Approval testing library for ruby
17
14
  email: approvaltests@dangilkerson.com
18
15
  executables: []
19
-
20
16
  extensions: []
21
-
22
- extra_rdoc_files:
17
+ extra_rdoc_files:
23
18
  - README
24
- files:
19
+ files:
20
+ - Gemfile
21
+ - Gemfile.lock
25
22
  - README
26
23
  - Rakefile
27
24
  - VERSION
28
25
  - approval_tests.gemspec
26
+ - cucumber.yml
27
+ - features/.approved.txt
28
+ - features/.received.txt
29
+ - features/basic_approval.approves_string.approved.txt
30
+ - features/basic_approval.feature
31
+ - features/basic_approval_approves_string.approved.txt
32
+ - features/step_definitions/basic_steps.rb
33
+ - features/support/env.rb
34
+ - features/support/paths.rb
29
35
  - lib/approval_tests.rb
30
36
  - lib/approval_tests/approvals.rb
37
+ - lib/approval_tests/approvers.rb
31
38
  - lib/approval_tests/approvers/file_approver.rb
39
+ - lib/approval_tests/extensions/cucumber.rb
32
40
  - lib/approval_tests/extensions/rspec.rb
41
+ - lib/approval_tests/namers.rb
42
+ - lib/approval_tests/namers/cucumber_namer.rb
33
43
  - lib/approval_tests/namers/rspec_namer.rb
44
+ - lib/approval_tests/reporters.rb
45
+ - lib/approval_tests/reporters/cleanup_reporter.rb
34
46
  - lib/approval_tests/reporters/diff_reporter.rb
47
+ - lib/approval_tests/reporters/file_launcher_reporter.rb
48
+ - lib/approval_tests/reporters/opendiff_reporter.rb
35
49
  - lib/approval_tests/reporters/quiet_reporter.rb
50
+ - lib/approval_tests/reporters/rspec_reporter.rb
36
51
  - lib/approval_tests/reporters/text_mate_reporter.rb
52
+ - lib/approval_tests/reporters/tortoisediff_reporter.rb
53
+ - lib/approval_tests/reporters/vimdiff_reporter.rb
54
+ - lib/approval_tests/utils.rb
55
+ - lib/approval_tests/writers.rb
37
56
  - lib/approval_tests/writers/html_writer.rb
38
57
  - lib/approval_tests/writers/text_writer.rb
39
58
  - lib/approval_tests/writers/xml_writer.rb
40
- - spec/a.txt
41
- - spec/approvals_lists_should_show_empty_lists.approved.txt
42
- - spec/approvals_lists_should_write_arrays.approved.txt
43
- - spec/approvals_lists_should_write_maps.approved.txt
44
- - spec/approvals_multiple_describes_should_approve_multiple_describes.approved.txt
45
- - spec/approvals_should_approve_shared_behaviors.approved.txt
46
- - spec/approvals_should_successfully_approve_text.approved.txt
47
- - spec/approvals_spec.rb
48
- - spec/approvals_using_approval_blocks.approved.txt
49
- - spec/approvals_using_approval_blocks_the_last_statement.approved.txt
50
- - spec/approvals_xml_should_be_pretty.approved.txt
51
- - spec/b.txt
52
- - spec/cleanup_reporter.rb
53
- - spec/spec.opts
59
+ - spec/approval_tests/a.txt
60
+ - spec/approval_tests/approvals_it_should_behave_like_shared_behaviors_should_approve_shared_behaviors.approved.txt
61
+ - spec/approval_tests/approvals_lists_should_show_empty_lists.approved.txt
62
+ - spec/approval_tests/approvals_lists_should_write_arrays.approved.txt
63
+ - spec/approval_tests/approvals_lists_should_write_maps.approved.txt
64
+ - spec/approval_tests/approvals_multiple_describes_should_approve_multiple_describes.approved.txt
65
+ - spec/approval_tests/approvals_should_approve_shared_behaviors.approved.txt
66
+ - spec/approval_tests/approvals_should_successfully_approve_text.approved.txt
67
+ - spec/approval_tests/approvals_spec.rb
68
+ - spec/approval_tests/approvals_using_approval_blocks.approved.txt
69
+ - spec/approval_tests/approvals_using_approval_blocks_the_last_statement.approved.txt
70
+ - spec/approval_tests/approvals_xml_should_be_pretty.approved.txt
71
+ - spec/approval_tests/b.txt
72
+ - spec/approval_tests/reporter_spec.rb
73
+ - spec/approval_tests/self_example_group_full_description.received.txt
74
+ - spec/approval_tests/system_spec.rb
54
75
  - spec/spec_helper.rb
55
- has_rdoc: true
56
- homepage: http://github.com/approvaltests/approval_tests
76
+ homepage: http://github.com/approvals/approval_tests
57
77
  licenses: []
58
-
78
+ metadata: {}
59
79
  post_install_message:
60
- rdoc_options:
80
+ rdoc_options:
61
81
  - --charset=UTF-8
62
- require_paths:
82
+ require_paths:
63
83
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
69
- version:
70
- required_rubygems_version: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: "0"
75
- version:
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
76
94
  requirements: []
77
-
78
95
  rubyforge_project: approvaltests
79
- rubygems_version: 1.3.4
96
+ rubygems_version: 2.0.3
80
97
  signing_key:
81
98
  specification_version: 3
82
99
  summary: Approval testing library
83
- test_files:
84
- - spec/approvals_spec.rb
85
- - spec/cleanup_reporter.rb
86
- - spec/spec_helper.rb
100
+ test_files: []
101
+ has_rdoc:
@@ -1 +0,0 @@
1
- [name] = harry