foca-storyteller 0.1.0 → 0.1.1
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.yml +1 -1
- data/lib/storyteller.rb +56 -19
- data/storyteller.gemspec +2 -2
- data/test/fixtures/test_example.rb +17 -0
- data/test/test_storyteller.rb +45 -0
- metadata +5 -1
data/VERSION.yml
CHANGED
data/lib/storyteller.rb
CHANGED
@@ -1,29 +1,66 @@
|
|
1
|
+
require "rubygems"
|
1
2
|
require "context"
|
2
3
|
|
3
|
-
module Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Test
|
5
|
+
# Including Storyteller in your TestCase allows you to declare a user story
|
6
|
+
# (global to the entire test case) and then run `scenarios' (tests) regarding
|
7
|
+
# that user story
|
8
|
+
#
|
9
|
+
# For example:
|
10
|
+
#
|
11
|
+
# class MyTestCase < Test::Unit::TestCase
|
12
|
+
# include Test::Storyteller
|
13
|
+
#
|
14
|
+
# story <<-EOS
|
15
|
+
# As a <role>
|
16
|
+
# I want to <feature>
|
17
|
+
# So that <profit>
|
18
|
+
# EOS
|
19
|
+
#
|
20
|
+
# scenario "some scenario description" do
|
21
|
+
# ...
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
module Storyteller
|
25
|
+
def self.included(base)
|
26
|
+
base.before(:all) do
|
27
|
+
puts
|
28
|
+
print Storyteller.color.first
|
29
|
+
print self.class.story.to_s.gsub(/^\s+/, '')
|
30
|
+
print Storyteller.color.last
|
31
|
+
end
|
32
|
+
|
33
|
+
base.after(:all) do
|
34
|
+
puts
|
35
|
+
end
|
36
|
+
|
37
|
+
class << base
|
38
|
+
alias :scenario :test
|
39
|
+
end
|
40
|
+
|
41
|
+
base.extend ClassMethods
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
def story(story=nil)
|
46
|
+
@story = story if story
|
47
|
+
@story
|
48
|
+
end
|
10
49
|
end
|
11
50
|
|
12
|
-
|
13
|
-
|
51
|
+
def self.color=(color)
|
52
|
+
if color
|
53
|
+
@start_color = "\e[#{color}m"
|
54
|
+
@end_color = "\e[0m"
|
55
|
+
else
|
56
|
+
@start_color = @end_color = nil
|
57
|
+
end
|
14
58
|
end
|
15
59
|
|
16
|
-
|
17
|
-
|
60
|
+
def self.color
|
61
|
+
[@start_color, @end_color]
|
18
62
|
end
|
19
63
|
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
module ClassMethods
|
24
|
-
def story(story=nil)
|
25
|
-
@story = story if story
|
26
|
-
@story
|
27
|
-
end
|
64
|
+
self.color = 36 # cyan
|
28
65
|
end
|
29
66
|
end
|
data/storyteller.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{storyteller}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nicol\303\241s Sanguinetti"]
|
9
9
|
s.date = %q{2008-12-30}
|
10
10
|
s.description = %q{Minimalist user story runner on top of test/unit}
|
11
11
|
s.email = %q{contacto@nicolassanguinetti.info}
|
12
|
-
s.files = ["lib", "lib/storyteller.rb", "Rakefile", "README.markdown", "storyteller.gemspec", "VERSION.yml"]
|
12
|
+
s.files = ["lib", "lib/storyteller.rb", "Rakefile", "README.markdown", "storyteller.gemspec", "test", "test/fixtures", "test/fixtures/test_example.rb", "test/test_storyteller.rb", "VERSION.yml"]
|
13
13
|
s.homepage = %q{http://nicolassanguinetti.info}
|
14
14
|
s.require_paths = ["lib"]
|
15
15
|
s.rubyforge_project = %q{storyteller}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ExampleStorytellerTest < Test::Unit::TestCase
|
2
|
+
include Test::Storyteller
|
3
|
+
|
4
|
+
story <<-EOS
|
5
|
+
As a tester
|
6
|
+
I want pretty output from my stories
|
7
|
+
So I can see how nice they look
|
8
|
+
EOS
|
9
|
+
|
10
|
+
scenario "Running a successful scenario" do
|
11
|
+
assert true
|
12
|
+
end
|
13
|
+
|
14
|
+
scenario "Running another scenario" do
|
15
|
+
assert true
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lib/storyteller"
|
2
|
+
require "test/unit"
|
3
|
+
require "redgreen"
|
4
|
+
|
5
|
+
# Quick and dirty way to test our output
|
6
|
+
class StdoutStub
|
7
|
+
attr_accessor :text
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@text = ""
|
11
|
+
end
|
12
|
+
|
13
|
+
def write(text)
|
14
|
+
@text += text.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def puts(text)
|
18
|
+
write(text.to_s + "\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
def flush
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class TestStoryteller < Test::Unit::TestCase
|
26
|
+
def test_it_displays_the_story_in_color
|
27
|
+
output = capturing_stdout { run_fixtures }
|
28
|
+
assert_match /\e\[36mAs a tester\nI want pretty output from my stories\nSo I can see how nice they look\n\e\[0m\e\[32m\.\e\[0m\e\[32m\.\e\[0m\n/, output
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def run_fixtures
|
34
|
+
Test::Unit::AutoRunner.run(true, File.dirname(__FILE__) + "/fixtures", [])
|
35
|
+
end
|
36
|
+
|
37
|
+
def capturing_stdout
|
38
|
+
old = $stdout
|
39
|
+
$> = StdoutStub.new
|
40
|
+
yield
|
41
|
+
output = $>.text
|
42
|
+
$> = old
|
43
|
+
output
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foca-storyteller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Nicol\xC3\xA1s Sanguinetti"
|
@@ -35,6 +35,10 @@ files:
|
|
35
35
|
- Rakefile
|
36
36
|
- README.markdown
|
37
37
|
- storyteller.gemspec
|
38
|
+
- test
|
39
|
+
- test/fixtures
|
40
|
+
- test/fixtures/test_example.rb
|
41
|
+
- test/test_storyteller.rb
|
38
42
|
- VERSION.yml
|
39
43
|
has_rdoc: false
|
40
44
|
homepage: http://nicolassanguinetti.info
|