gmalamid-synthesis 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,12 +65,13 @@ To use with Expectations, redirecting output to a file:
65
65
  t.out = File.new "synthesis.test.txt", "a"
66
66
  end
67
67
 
68
- To output a DOT graph:
68
+ To output a DOT graph, with an output file called "synthesis.dot" (if formatter_out is not specified, the default ouput is STDOUT):
69
69
 
70
70
  require "synthesis/task"
71
71
 
72
72
  Synthesis::Task.new do |t|
73
73
  t.formatter = :dot
74
+ t.formatter_out = "synthesis.dot"
74
75
  end
75
76
 
76
77
  To use Synthesis with Rails:
@@ -79,6 +80,7 @@ To use Synthesis with Rails:
79
80
 
80
81
  Synthesis::Task.new do |t|
81
82
  RAILS_ENV = "test"
83
+ Rake::Task['environment'].invoke # This loads the Rails environment, which may make your build slower. Use only if needed
82
84
  t.pattern = 'test/**/*_test.rb'
83
85
  end
84
86
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ task :test => %w[test:core test:mocha test:spec]
13
13
 
14
14
  desc "Run core tests"
15
15
  Rake::TestTask.new('test:core') do |t|
16
- t.pattern = 'test/synthesis/*_test.rb'
16
+ t.pattern = '{test/synthesis/,test/synthesis/formatter/}*_test.rb'
17
17
  end
18
18
 
19
19
  desc "Run Mocha adapter tests"
@@ -1,16 +1,20 @@
1
1
  module Synthesis
2
2
  class Formatter
3
+ def initialize(out)
4
+ @out = out
5
+ end
6
+
3
7
  def report_tested_expectations
4
- ExpectationRecord.tested_expectations.each { |e| puts e.to_report }
8
+ ExpectationRecord.tested_expectations.each { |e| @out.puts e.to_report }
5
9
  end
6
10
 
7
11
  def report_untested_expectations
8
- ExpectationRecord.untested_expectations.each { |e| puts e.to_report }
12
+ ExpectationRecord.untested_expectations.each { |e| @out.puts e.to_report }
9
13
  end
10
14
 
11
15
  class << self
12
- def load
13
- @formatter.new
16
+ def load(out)
17
+ @formatter.new(out)
14
18
  end
15
19
 
16
20
  def inherited(subclass)
@@ -4,22 +4,23 @@ require "sexp_processor"
4
4
 
5
5
  module Synthesis
6
6
  class DotFormatter < Formatter
7
- def initialize
7
+ def initialize(out)
8
+ super
8
9
  Expectation::Expectation.send(:include, ExpectationReportFormat::Dot)
9
10
  end
10
11
 
11
12
  def digraph
12
- puts "digraph synthesis_expectations {"
13
- puts " rankdir=LR;"
14
- puts " size=\"8,10\";"
15
- puts " ratio=\"fill\";"
16
- puts " node [shape = circle];"
17
- puts " edge [color = green]"
13
+ @out.puts "digraph synthesis_expectations {"
14
+ @out.puts " rankdir=LR;"
15
+ @out.puts " size=\"8,10\";"
16
+ @out.puts " ratio=\"fill\";"
17
+ @out.puts " node [shape = circle];"
18
+ @out.puts " edge [color = green]"
18
19
  report_tested_expectations
19
- puts
20
- puts " edge [color = red]"
20
+ @out.puts
21
+ @out.puts " edge [color = red]"
21
22
  report_untested_expectations
22
- puts "}"
23
+ @out.puts "}"
23
24
  end
24
25
  alias format_failure digraph
25
26
  alias format_success digraph
@@ -2,22 +2,27 @@ module Synthesis
2
2
  class TextFormatter < Formatter
3
3
  include Logging
4
4
 
5
- def initialize
5
+ def initialize(out)
6
+ super
6
7
  Expectation::Expectation.send(:include, ExpectationReportFormat::Text)
7
8
  end
8
9
 
9
10
  def format_success
10
- log; log "Verified #{ExpectationRecord.expectations.size} expectations"
11
- log "SUCCESS."
11
+ @out.puts "[Synthesis] "
12
+ @out.puts "[Synthesis] Verified #{ExpectationRecord.expectations.size} expectations"
13
+ @out.puts "[Synthesis] SUCCESS."
12
14
  end
13
15
 
14
16
  def format_failure
15
- log; log "Tested Expectations: "
17
+ @out.puts "[Synthesis] "
18
+ @out.puts "[Synthesis] Tested Expectations: "
16
19
  report_tested_expectations
17
- log; log "Untested Expectations: "
20
+ @out.puts "[Synthesis] "
21
+ @out.puts "[Synthesis] Untested Expectations: "
18
22
  report_untested_expectations
19
- log "Ignoring: #{ExpectationRecord.ignored.to_a * ', '}"
20
- log; log "FAILED."
23
+ @out.puts "[Synthesis] Ignoring: #{ExpectationRecord.ignored.to_a * ', '}"
24
+ @out.puts "[Synthesis] "
25
+ @out.puts "[Synthesis] FAILED."
21
26
  end
22
27
  end
23
28
 
@@ -1,13 +1,25 @@
1
1
  module Synthesis
2
2
  class Reporter
3
- def self.report
4
- formatter = Formatter.load
5
- if ExpectationRecord.has_untested_expectations?
6
- formatter.format_failure
7
- return -1
3
+ def self.report(format, formatter_out)
4
+ begin
5
+ require "synthesis/formatter/#{format}"
6
+ rescue LoadError
7
+ raise "Invalid format: #{format}"
8
8
  end
9
- formatter.format_success
10
- 0
9
+ out = formatter_out ? File.open(formatter_out, 'w') : STDOUT
10
+ result = 0
11
+ begin
12
+ formatter = Formatter.load(out)
13
+ if ExpectationRecord.has_untested_expectations?
14
+ formatter.format_failure
15
+ result = -1
16
+ else
17
+ formatter.format_success
18
+ end
19
+ ensure
20
+ out.close unless out == STDOUT
21
+ end
22
+ return result
11
23
  end
12
24
  end
13
25
  end
@@ -1,10 +1,13 @@
1
1
  module Synthesis
2
2
  class Runner
3
- def self.run(adapter, pattern, formatter)
4
- require "synthesis/adapter/#{adapter}"
5
- require "synthesis/formatter/#{formatter}"
3
+ def self.run(adapter, pattern, formatter, formatter_out)
4
+ begin
5
+ require "synthesis/adapter/#{adapter}"
6
+ rescue LoadError
7
+ raise "Invalid adapter: #{adapter}"
8
+ end
6
9
  Adapter.load(pattern).run
7
- at_exit { Reporter.report unless $! }
10
+ at_exit { Reporter.report(formatter, formatter_out) unless $! }
8
11
  end
9
12
  end
10
13
  end
@@ -7,7 +7,7 @@ module Synthesis
7
7
  class Task < Rake::TaskLib
8
8
  include Logging
9
9
  attr_accessor :verbose, :pattern, :ruby_opts
10
- attr_accessor :adapter, :out, :ignored, :libs, :formatter
10
+ attr_accessor :adapter, :out, :ignored, :libs, :formatter, :formatter_out
11
11
 
12
12
  def initialize(name='synthesis:test')
13
13
  @name, @ignored, @libs = name, [], []
@@ -39,7 +39,7 @@ module Synthesis
39
39
  require File.dirname(__FILE__) + "/../synthesis/runner"
40
40
  Synthesis::Logging.const_set(:OUT, @out) if @out
41
41
  Synthesis::ExpectationRecord.ignore(*@ignored)
42
- Synthesis::Runner.run(@adapter, @pattern, @formatter)
42
+ Synthesis::Runner.run(@adapter, @pattern, @formatter, @formatter_out)
43
43
  end
44
44
  end
45
45
  self
data/synthesis.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  GEMSPEC =Gem::Specification.new do |s|
2
2
  s.name = 'synthesis'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.1'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.rubyforge_project = "synthesis"
6
6
  s.summary, s.description = 'A tool for Synthesized Testing'
@@ -8,12 +8,12 @@ GEMSPEC =Gem::Specification.new do |s|
8
8
  s.email = 'george@nutrun.com'
9
9
  s.homepage = 'http://synthesis.rubyforge.org'
10
10
  s.has_rdoc = true
11
- s.rdoc_options += ['--quiet', '--title', 'Synthesis', '--main', 'README', '--inline-source']
12
- s.extra_rdoc_files = ['README', 'COPYING']
11
+ s.rdoc_options += ['--quiet', '--title', 'Synthesis', '--main', 'README.rdoc', '--inline-source']
12
+ s.extra_rdoc_files = ['README.rdoc', 'COPYING']
13
13
  s.files = [
14
14
  "COPYING",
15
15
  "Rakefile",
16
- "README",
16
+ "README.rdoc",
17
17
  "synthesis.gemspec",
18
18
  "lib/synthesis/adapter/expectations.rb",
19
19
  "lib/synthesis/adapter/mocha.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmalamid-synthesis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Caborn, George Malamidis, Danilo Sato
@@ -20,12 +20,12 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README
23
+ - README.rdoc
24
24
  - COPYING
25
25
  files:
26
26
  - COPYING
27
27
  - Rakefile
28
- - README
28
+ - README.rdoc
29
29
  - synthesis.gemspec
30
30
  - lib/synthesis/adapter/expectations.rb
31
31
  - lib/synthesis/adapter/mocha.rb
@@ -60,7 +60,7 @@ rdoc_options:
60
60
  - --title
61
61
  - Synthesis
62
62
  - --main
63
- - README
63
+ - README.rdoc
64
64
  - --inline-source
65
65
  require_paths:
66
66
  - lib