any-spec 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/any-spec.gemspec +5 -3
- data/lib/any-spec/assertions.rb +7 -7
- data/lib/any-spec/string_extensions.rb +42 -0
- data/lib/any-spec/test-runner.rb +17 -11
- data/test/unit/assertions_test.rb +11 -6
- metadata +5 -3
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/any-spec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{any-spec}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Gough"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-05}
|
13
13
|
s.description = %q{AnySpec is a framework for writing executable language specifications and automated black-box functional tests for programming languages.}
|
14
14
|
s.email = %q{aaron@aarongough.com}
|
15
15
|
s.executables = ["any-spec", "any-spec"]
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
"README.rdoc"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
|
-
"
|
21
|
+
".gitignore",
|
22
|
+
"MIT-LICENSE",
|
22
23
|
"README.rdoc",
|
23
24
|
"Rakefile",
|
24
25
|
"VERSION",
|
@@ -26,6 +27,7 @@ Gem::Specification.new do |s|
|
|
26
27
|
"bin/any-spec",
|
27
28
|
"lib/any-spec.rb",
|
28
29
|
"lib/any-spec/assertions.rb",
|
30
|
+
"lib/any-spec/string_extensions.rb",
|
29
31
|
"lib/any-spec/test-case.rb",
|
30
32
|
"lib/any-spec/test-runner.rb",
|
31
33
|
"test/fixtures/example_test_specification.yml",
|
data/lib/any-spec/assertions.rb
CHANGED
@@ -6,29 +6,29 @@ module AnySpec
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def flunk
|
9
|
-
message = "Flunked."
|
9
|
+
message = "Flunked.".indent(3).red
|
10
10
|
assert_block(message) { false }
|
11
11
|
end
|
12
12
|
|
13
13
|
def assert( expression )
|
14
|
-
message = "#{expression.inspect} is not true"
|
14
|
+
message = "#{expression.inspect} is not true".indent(3).red
|
15
15
|
assert_block(message) { expression == true }
|
16
16
|
end
|
17
17
|
|
18
18
|
def assert_output(expected, output = @test_case.test_output)
|
19
|
-
message = "Expected output to be:\n<#{expected.inspect}> but was:\n<#{output.inspect}>"
|
19
|
+
message = "Expected output to be:\n<#{expected.inspect}> but was:\n<#{output.inspect}>".indent(3).red
|
20
20
|
assert_block(message) { output == expected }
|
21
21
|
end
|
22
22
|
|
23
23
|
def assert_execution_success
|
24
|
-
message = "Execution of test case failed when it was expected to succeed:\n"
|
25
|
-
message += @test_case.test_output
|
24
|
+
message = "Execution of test case failed when it was expected to succeed:\n".indent(3).red
|
25
|
+
message += @test_case.test_output.prefix_each_line_with("# ").indent(4).grey
|
26
26
|
assert_block(message) { @test_case.exit_status == 0 }
|
27
27
|
end
|
28
28
|
|
29
29
|
def assert_execution_failure
|
30
|
-
message = "Execution of test case succeeded when it was expected to fail:\n"
|
31
|
-
message +=
|
30
|
+
message = " Execution of test case succeeded when it was expected to fail:\n"
|
31
|
+
message += @test_case.test_output.prefix_each_line_with("# ").indent(4).grey
|
32
32
|
assert_block(message) { @test_case.exit_status != 0 }
|
33
33
|
end
|
34
34
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def indent(level)
|
4
|
+
return self.lines.map {|line|
|
5
|
+
(" " * level) + line
|
6
|
+
}.join
|
7
|
+
end
|
8
|
+
|
9
|
+
def prefix_each_line_with(string)
|
10
|
+
return self.lines.map {|line|
|
11
|
+
string + line
|
12
|
+
}.join
|
13
|
+
end
|
14
|
+
|
15
|
+
def red
|
16
|
+
self.colorize(:red)
|
17
|
+
end
|
18
|
+
|
19
|
+
def green
|
20
|
+
self.colorize(:green)
|
21
|
+
end
|
22
|
+
|
23
|
+
def white
|
24
|
+
self.colorize(:white)
|
25
|
+
end
|
26
|
+
|
27
|
+
def grey
|
28
|
+
self.colorize(:grey)
|
29
|
+
end
|
30
|
+
|
31
|
+
def colorize(color)
|
32
|
+
reset_string = "\e[0m"
|
33
|
+
case color
|
34
|
+
when :white then color_string = "\e[37m"
|
35
|
+
when :red then color_string = "\e[31m"
|
36
|
+
when :green then color_string = "\e[32m"
|
37
|
+
when :grey then color_string = "\e[90m"
|
38
|
+
end
|
39
|
+
return color_string + self + reset_string
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/any-spec/test-runner.rb
CHANGED
@@ -30,36 +30,42 @@ module AnySpec
|
|
30
30
|
def run_tests(silence = false)
|
31
31
|
@report = ""
|
32
32
|
@silence = silence
|
33
|
-
message "\nLoaded suite: #{@test_specification_file}\n"
|
34
|
-
message "Targeting: #{@target_executable}\n"
|
35
33
|
message "\nStarted\n"
|
36
34
|
start_time = Time.now
|
37
35
|
assertions = 0
|
38
36
|
failed_tests = []
|
39
37
|
@test_cases.each do |test_case|
|
40
38
|
result = test_case.run
|
41
|
-
message "." if(result)
|
42
|
-
message "F" if(!result)
|
39
|
+
message ".", :green if(result)
|
40
|
+
message "F", :red if(!result)
|
43
41
|
assertions += test_case.assertions
|
44
42
|
failed_tests << test_case if(!result)
|
45
43
|
end
|
46
|
-
message "\
|
44
|
+
message "\n\n"
|
45
|
+
message "Failures:\n\n" unless failed_tests.empty?
|
47
46
|
failed_tests.each_index do |x|
|
48
47
|
test_case = failed_tests[x]
|
49
|
-
message " #{x + 1})
|
50
|
-
message "In file: " + test_case.path.gsub(File.split(@test_specification_file)[0], "") + "\n"
|
48
|
+
message " #{x + 1}) " + test_case.path.gsub(File.split(@test_specification_file)[0], "") + "\n"
|
51
49
|
message test_case.message + "\n\n"
|
52
50
|
end
|
53
|
-
|
54
|
-
|
51
|
+
message "\n\nFinished in #{(Time.now - start_time).to_f} seconds.\n"
|
52
|
+
pass_rate = format("%.2f",(100.0 - ((failed_tests.length.to_f) / @test_cases.length) * 100))
|
53
|
+
result_color = failed_tests.count == 0 ? :green : :red
|
54
|
+
message "#{@test_cases.length} tests, #{assertions} assertions, #{failed_tests.count} failures, #{pass_rate}% pass rate\n", result_color
|
55
55
|
return @test_cases
|
56
56
|
end
|
57
57
|
|
58
|
-
def message(string)
|
58
|
+
def message(string, color = :white)
|
59
59
|
if(@silence)
|
60
60
|
@report << string
|
61
61
|
else
|
62
|
-
|
62
|
+
case color
|
63
|
+
when :white then print( "\e[37m" )
|
64
|
+
when :red then print( "\e[31m" )
|
65
|
+
when :green then print( "\e[32m" )
|
66
|
+
when :grey then print( "\e[90m")
|
67
|
+
end
|
68
|
+
print string + "\e[0m"
|
63
69
|
$stdout.flush
|
64
70
|
end
|
65
71
|
end
|
@@ -33,7 +33,7 @@ class AssertionsTest < Test::Unit::TestCase
|
|
33
33
|
test "flunk should flunk" do
|
34
34
|
AnySpec::Assertions.new(@test_case).flunk
|
35
35
|
assert_equal false, @test_case.last_assertion_result
|
36
|
-
|
36
|
+
assert @test_case.message.include? "Flunked."
|
37
37
|
end
|
38
38
|
|
39
39
|
test "assert should assert truthiness" do
|
@@ -45,13 +45,13 @@ class AssertionsTest < Test::Unit::TestCase
|
|
45
45
|
test "assert should fail on false" do
|
46
46
|
AnySpec::Assertions.new(@test_case).assert(false)
|
47
47
|
assert_equal false, @test_case.last_assertion_result
|
48
|
-
|
48
|
+
assert @test_case.message.include? "false is not true"
|
49
49
|
end
|
50
50
|
|
51
51
|
test "assert should fail on nil" do
|
52
52
|
AnySpec::Assertions.new(@test_case).assert(nil)
|
53
53
|
assert_equal false, @test_case.last_assertion_result
|
54
|
-
|
54
|
+
assert @test_case.message.include? "nil is not true"
|
55
55
|
end
|
56
56
|
|
57
57
|
test "assert_output should pass when output matches" do
|
@@ -65,7 +65,10 @@ class AssertionsTest < Test::Unit::TestCase
|
|
65
65
|
@test_case.test_output = "test2"
|
66
66
|
AnySpec::Assertions.new(@test_case).assert_output("test")
|
67
67
|
assert_equal false, @test_case.last_assertion_result
|
68
|
-
|
68
|
+
assert @test_case.message.include? "Expected output to be:"
|
69
|
+
assert @test_case.message.include? '<"test">'
|
70
|
+
assert @test_case.message.include? 'but was:'
|
71
|
+
assert @test_case.message.include? '<"test2">'
|
69
72
|
end
|
70
73
|
|
71
74
|
test "assert_execution_success should pass when exit_status == 0" do
|
@@ -81,7 +84,8 @@ class AssertionsTest < Test::Unit::TestCase
|
|
81
84
|
@test_case.exit_status = 1
|
82
85
|
AnySpec::Assertions.new(@test_case).assert_execution_success
|
83
86
|
assert_equal false, @test_case.last_assertion_result
|
84
|
-
|
87
|
+
assert @test_case.message.include? "Execution of test case failed when it was expected to succeed:"
|
88
|
+
assert @test_case.message.include? "test2"
|
85
89
|
end
|
86
90
|
|
87
91
|
test "assert_execution_failure should fail when exit_status == 0" do
|
@@ -89,7 +93,8 @@ class AssertionsTest < Test::Unit::TestCase
|
|
89
93
|
@test_case.exit_status = 0
|
90
94
|
AnySpec::Assertions.new(@test_case).assert_execution_failure
|
91
95
|
assert_equal false, @test_case.last_assertion_result
|
92
|
-
|
96
|
+
assert @test_case.message.include? "Execution of test case succeeded when it was expected to fail:"
|
97
|
+
assert @test_case.message.include? "test2"
|
93
98
|
end
|
94
99
|
|
95
100
|
test "assert_execution_failure should pass when exit_status != 0" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aaron Gough
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-03-05 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -29,6 +29,7 @@ extra_rdoc_files:
|
|
29
29
|
- MIT-LICENSE
|
30
30
|
- README.rdoc
|
31
31
|
files:
|
32
|
+
- .gitignore
|
32
33
|
- MIT-LICENSE
|
33
34
|
- README.rdoc
|
34
35
|
- Rakefile
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- bin/any-spec
|
38
39
|
- lib/any-spec.rb
|
39
40
|
- lib/any-spec/assertions.rb
|
41
|
+
- lib/any-spec/string_extensions.rb
|
40
42
|
- lib/any-spec/test-case.rb
|
41
43
|
- lib/any-spec/test-runner.rb
|
42
44
|
- test/fixtures/example_test_specification.yml
|