riot 0.10.3 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/riot/context.rb +10 -5
- data/lib/riot/reporter.rb +19 -22
- data/riot.gemspec +2 -2
- data/test/context_test.rb +4 -4
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.
|
1
|
+
0.10.4
|
data/lib/riot/context.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module Riot
|
2
|
+
RootContext = Struct.new(:setups)
|
2
3
|
class Context
|
3
|
-
def initialize(description,
|
4
|
+
def initialize(description, parent=RootContext.new([]), &definition)
|
5
|
+
@parent = parent
|
4
6
|
@description = description
|
5
|
-
@contexts, @setups, @assertions = [],
|
7
|
+
@contexts, @setups, @assertions = [], [], []
|
6
8
|
self.instance_eval(&definition)
|
7
9
|
end
|
8
10
|
|
@@ -10,18 +12,21 @@ module Riot
|
|
10
12
|
@setups << Setup.new(&definition)
|
11
13
|
end
|
12
14
|
|
15
|
+
def setups
|
16
|
+
@parent.setups + @setups
|
17
|
+
end
|
18
|
+
|
13
19
|
def asserts(what, &definition) new_assertion("asserts", what, &definition); end
|
14
20
|
def should(what, &definition) new_assertion("should", what, &definition); end
|
15
21
|
|
16
22
|
def asserts_topic; asserts("topic") { topic }; end
|
17
23
|
|
18
24
|
def context(description, &definition)
|
19
|
-
#
|
20
|
-
@contexts << Context.new("#{@description} #{description}", @setups.dup, &definition)
|
25
|
+
@contexts << Context.new("#{@description} #{description}", self, &definition)
|
21
26
|
end
|
22
27
|
|
23
28
|
def run(reporter)
|
24
|
-
runnables =
|
29
|
+
runnables = setups + @assertions
|
25
30
|
reporter.describe_context(@description) unless @assertions.empty?
|
26
31
|
situation = Situation.new
|
27
32
|
runnables.each do |runnable|
|
data/lib/riot/reporter.rb
CHANGED
@@ -46,27 +46,38 @@ module Riot
|
|
46
46
|
values = [passes, failures, errors, ("%0.6f" % time_taken)]
|
47
47
|
say "\n%d passes, %d failures, %d errors in %s seconds" % values
|
48
48
|
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
raise LoadError if ENV["TM_MODE"]
|
52
|
+
require 'rubygems'
|
53
|
+
require 'term/ansicolor'
|
54
|
+
include Term::ANSIColor
|
55
|
+
rescue LoadError
|
56
|
+
def green(str); str; end
|
57
|
+
alias :red :green
|
58
|
+
alias :yellow :green
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
51
62
|
class StoryReporter < IOReporter
|
52
63
|
def describe_context(description) say description; end
|
53
|
-
def pass(description) say " + " + description
|
54
|
-
def fail(description, message) say " - " + "#{description}: #{message}"
|
55
|
-
def error(description, e) say " ! " + "#{description}: #{e.message}"
|
64
|
+
def pass(description) say " + " + green(description); end
|
65
|
+
def fail(description, message) say " - " + yellow("#{description}: #{message}"); end
|
66
|
+
def error(description, e) say " ! " + red("#{description}: #{e.message}"); end
|
56
67
|
end
|
57
68
|
|
58
69
|
class VerboseStoryReporter < StoryReporter
|
59
70
|
def error(description, e)
|
60
71
|
super(description, e)
|
61
|
-
say " #{e.class.name} occured"
|
62
|
-
e.backtrace.each { |line| say " at #{line}"
|
72
|
+
say red(" #{e.class.name} occured")
|
73
|
+
e.backtrace.each { |line| say red(" at #{line}") }
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
66
77
|
class DotMatrixReporter < IOReporter
|
67
|
-
def pass(description); writer.write "."
|
68
|
-
def fail(description, message); writer.write "F"
|
69
|
-
def error(description, e); writer.write "E"
|
78
|
+
def pass(description); writer.write green("."); end
|
79
|
+
def fail(description, message); writer.write yellow("F"); end
|
80
|
+
def error(description, e); writer.write red("E"); end
|
70
81
|
# TODO: Print the failures and errors at the end. Sorry :|
|
71
82
|
end
|
72
83
|
|
@@ -77,17 +88,3 @@ module Riot
|
|
77
88
|
def results(time_taken); end
|
78
89
|
end
|
79
90
|
end # Riot
|
80
|
-
|
81
|
-
# Colorize strings
|
82
|
-
class ::String
|
83
|
-
begin
|
84
|
-
raise LoadError if ENV["TM_MODE"]
|
85
|
-
require 'rubygems'
|
86
|
-
require 'term/ansicolor'
|
87
|
-
include Term::ANSIColor
|
88
|
-
rescue LoadError
|
89
|
-
def green; self; end
|
90
|
-
alias :red :green
|
91
|
-
alias :yellow :green
|
92
|
-
end
|
93
|
-
end
|
data/riot.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{riot}
|
8
|
-
s.version = "0.10.
|
8
|
+
s.version = "0.10.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin 'Gus' Knowlden"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-03}
|
13
13
|
s.description = %q{An extremely fast, expressive, and context-driven unit-testing framework. A replacement for all other testing frameworks. Protest the slow test.}
|
14
14
|
s.email = %q{gus@gusg.us}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/context_test.rb
CHANGED
@@ -17,14 +17,14 @@ end # Reporting a context
|
|
17
17
|
|
18
18
|
context "Defining a context with multiple setups" do
|
19
19
|
setup do
|
20
|
-
a_context = Riot::Context.new("foobar") do
|
20
|
+
@a_context = Riot::Context.new("foobar") do
|
21
21
|
setup { "foo" }
|
22
22
|
setup { topic + "bar" }
|
23
23
|
asserts("blah") { topic == "foobar" }
|
24
24
|
end
|
25
|
-
a_context.run(MockReporter.new)
|
25
|
+
@a_context.run(MockReporter.new)
|
26
26
|
end
|
27
|
-
|
27
|
+
asserts("has setups") { @a_context.setups.count }.equals(2)
|
28
28
|
asserts("all tests pass") { topic.passes == 1 }
|
29
29
|
end # Defining a context with multiple setups
|
30
30
|
|
@@ -59,7 +59,7 @@ context "Nesting a context" do
|
|
59
59
|
|
60
60
|
asserts("parent setups are called") { topic.passes == 1 }
|
61
61
|
end # with setups
|
62
|
-
end #
|
62
|
+
end # Nesting a context
|
63
63
|
|
64
64
|
context "Using should" do
|
65
65
|
setup do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin 'Gus' Knowlden
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-03 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|