Skip to content

Commit

Permalink
Move implementation to one file. Add package and doc tasks to Rakefile.
Browse files Browse the repository at this point in the history
git-svn-id: https://dwerg.net/svn/reckon@7 35234dff-7a11-4982-9623-4bb5ff92b2a7
  • Loading branch information
manfred committed Mar 19, 2008
1 parent a2aa2d7 commit 2f168e7
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 84 deletions.
60 changes: 59 additions & 1 deletion Rakefile
@@ -1,3 +1,19 @@
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rake/gempackagetask'
require 'rake/rdoctask'

NAME = 'reckon'
VERSIE = '0.1'
RDOC_OPTS = ['--quiet', '--title', "Reckon – Leaner automated testing",
"--opname", "index.html",
"--line-numbers",
"--main", "README",
"--charset", "utf-8",
"--inline-source"]
CLEAN.include ['pkg', 'doc', '*.gem']

desc "Run all tests by default"
task :default => :test

Expand All @@ -6,4 +22,46 @@ task :test do
Dir[File.dirname(__FILE__) + '/test/**/*_test.rb'].each do |file|
load file
end
end
end

desc 'Create documentation'
Rake::RDocTask.new("doc") do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.options += RDOC_OPTS
rdoc.main = "README"
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end

spec = Gem::Specification.new do |s|
s.name = NAME
s.version = VERSIE
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
s.extra_rdoc_files = ["README", "LICENSE"]
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|test)\/']
s.summary = "Lean framework for automated testing"
s.description = "Reckon is an automated testing framework that aims for simplicity, speed and readability."
s.author = "Manfred Stienstra"
s.email = 'manfred@fngtps.com'
s.homepage = 'https://dwerg.net/svn/reckon'
s.required_ruby_version = '>= 1.8.6'

s.files = %w(README LICENSE Rakefile) + Dir.glob("lib/**/*") + Dir.glob("examples/**/*")
s.require_path = "lib"
end

Rake::GemPackageTask.new(spec) do |p|
p.tar_command = "env COPYFILE_DISABLE=true tar"
p.need_tar = true
p.gem_spec = spec
end

task :install do
sh %{rake package}
sh %{sudo gem install pkg/#{NAME}-#{VERSIE}}
end

task :uninstall => [:clean] do
sh %{sudo gem uninstall #{NAME}}
end
95 changes: 93 additions & 2 deletions lib/test/reckon.rb
@@ -1,5 +1,96 @@
require 'test/reckon/expectation'
require 'test/reckon/reporter'
module Test #:nodoc
# = Reckon
#
# Please explain me!
module Reckon
class Expectation
COMPARISON_MAP = {
'==' => { true => '==', false => '!=' },
'>=' => { true => '>=', false => '=<' },
'<=' => { true => '<=', false => '=>' },
'>' => { true => '>', false => '<' },
'<' => { true => '<', false => '>' },
'=~' => { true => '=~', false => '!~' },
'!~' => { true => '!~', false => '=~' }
}

def initialize(expected_value, test_result, test_description)
@expected_value = expected_value
@test_result = test_result
@test_description = test_description
end

COMPARISON_MAP.keys.each do |method|
define_method(method) do |other|
compare(method, other)
end
end

private

def compare(method, other)
reporter = Test::Reckon::Reporter.instance
if (@expected_value == other) == @test_result
reporter.add_success
else
message = "#{@expected_value.inspect} #{COMPARISON_MAP[method][!@test_result]} #{other.inspect}"
reporter.add_failure(@test_description, message)
end
end
end

class Reporter
require 'singleton'
include Singleton

def initialize
@failures = 0
@successes = 0
@exceptions = 0
at_exit { print_stats }
end

def add_failure(test_description, message)
filename, line_number, line = extract_context(*caller(2).first.split(/:/, 2))

$stderr.puts "#{filename}:#{line_number}"
$stderr.puts " * #{test_description}"
$stderr.puts " tested: #{line.strip}"
$stderr.puts " but: #{message}"
@failures += 1
end

def add_exception(test_description, exception)
filename, line_number, line = extract_context(*exception.backtrace.first.split(/:/, 2))

$stderr.puts "#{filename}:#{line_number}"
$stderr.puts " * #{test_description}"
$stderr.puts " evaluated: #{line.strip}"
$stderr.puts " exception: #{exception.inspect}"
@exceptions += 1
end

def add_success
@successes += 1
end

def print_stats
$stderr.puts("\n") if (@failures + @exceptions) > 0
$stderr.puts("#{@successes} passed, #{@failures} failed, #{@exceptions} broken")
end

private

def extract_context(filename, line_number)
filename = File.expand_path(filename)
line_number = line_number.to_i

lines = File.readlines(filename)
[filename, line_number, lines[line_number-1]]
end
end
end
end

def testing(description)
saved = Marshal.dump instance_variables.inject({}) { |saved, name| saved[name] = instance_variable_get(name); saved }
Expand Down
27 changes: 0 additions & 27 deletions lib/test/reckon/expectation.rb

This file was deleted.

54 changes: 0 additions & 54 deletions lib/test/reckon/reporter.rb

This file was deleted.

0 comments on commit 2f168e7

Please sign in to comment.