citrusbyte-stories 0.0.4 → 0.0.5

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.
@@ -0,0 +1,58 @@
1
+ gem "prawn", "~> 0.4"
2
+ require "prawn"
3
+
4
+ module Stories
5
+ class Runner::PDF < Runner
6
+ def render_header(pdf)
7
+ end
8
+
9
+ def finished(elapsed_time)
10
+ super
11
+
12
+ Prawn::Document.generate("stories.pdf", :page_size => "A4") do |pdf|
13
+ render_header(pdf)
14
+
15
+ pdf.text "User Acceptance Tests", :size => 20, :style => :bold
16
+
17
+ pdf.move_down(15)
18
+
19
+ $stories.each do |story|
20
+ pdf.text story.name, :style => :bold
21
+
22
+ story.scenarios.each_with_index do |scenario,i|
23
+ scenario_leading = 15
24
+
25
+ pdf.span(pdf.bounds.width - scenario_leading, :position => scenario_leading) do
26
+ pdf.text "— #{scenario.name}"
27
+
28
+ pdf.fill_color "666666"
29
+
30
+ unless scenario.steps.empty? && scenario.assertions.empty?
31
+ pdf.span(pdf.bounds.width - 30, :position => 30) do
32
+ pdf.font_size(9) do
33
+ render_many(pdf, scenario.steps)
34
+ render_many(pdf, scenario.assertions)
35
+ end
36
+ end
37
+ end
38
+
39
+ pdf.move_down(5) unless i + 1 == story.scenarios.size
40
+
41
+ pdf.fill_color "000000"
42
+ end
43
+ end
44
+
45
+ pdf.move_down(10)
46
+ end
47
+ end
48
+ end
49
+
50
+ def render_many(pdf, elements)
51
+ elements.each do |el|
52
+ pdf.text el.to_s.gsub(/"([^"]+)"/) {
53
+ "“#{$1}”"
54
+ }
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,142 @@
1
+ require 'test/unit/ui/console/testrunner'
2
+
3
+ $stories = []
4
+
5
+ class Test::Unit::TestCase
6
+ class << self
7
+ alias original_story story
8
+ alias original_scenario scenario
9
+
10
+ def story(name, &block)
11
+ story = Stories::Story.new(name)
12
+
13
+ original_story(name) do
14
+ @@story = story
15
+ instance_eval(&block)
16
+ end
17
+
18
+ $stories << story
19
+ end
20
+
21
+ def scenario(name, &block)
22
+ scenario = Stories::Scenario.new(name)
23
+
24
+ original_scenario(name) do
25
+ @scenario = scenario
26
+ instance_eval(&block)
27
+ end
28
+
29
+ @@story.scenarios << scenario
30
+ end
31
+ end
32
+ end
33
+
34
+ module Stories
35
+ class Story
36
+ attr_accessor :name, :scenarios
37
+
38
+ def initialize(name)
39
+ @name = name
40
+ @scenarios = []
41
+ end
42
+ end
43
+
44
+ class Scenario
45
+ attr_accessor :name, :steps, :assertions
46
+
47
+ def initialize(name)
48
+ @name = name
49
+ @steps = []
50
+ @assertions = []
51
+ end
52
+ end
53
+
54
+ class Runner < Test::Unit::UI::Console::TestRunner
55
+ def test_finished(name)
56
+ end
57
+
58
+ def add_fault(fault)
59
+ @faults << fault
60
+ end
61
+
62
+ def finished(elapsed_time)
63
+ puts
64
+
65
+ $stories.each_with_index do |story,i|
66
+ puts "- #{story.name}"
67
+
68
+ story.scenarios.each do |scenario|
69
+ puts " #{scenario.name}"
70
+
71
+ unless scenario.steps.empty? && scenario.assertions.empty?
72
+ scenario.steps.each do |step|
73
+ puts " #{step}"
74
+ end
75
+
76
+ scenario.assertions.each do |assertion|
77
+ puts " #{assertion}"
78
+ end
79
+
80
+ puts
81
+ end
82
+ end
83
+
84
+ puts unless i + 1 == $stories.size
85
+ end
86
+
87
+ super
88
+ puts "%d stories, %d scenarios" % [$stories.size, $stories.inject(0) {|total,s| total + s.scenarios.size }]
89
+ end
90
+ end
91
+
92
+ module Webrat
93
+ def report(action, &block)
94
+ define_method(action) do |*args|
95
+ @scenario.steps << block.call(*args)
96
+ super
97
+ end
98
+ end
99
+
100
+ module_function :report
101
+ end
102
+ end
103
+
104
+ Test::Unit::AutoRunner::RUNNERS[:stories] = proc do |r|
105
+ Stories::Runner
106
+ end
107
+
108
+ Test::Unit::AutoRunner::RUNNERS[:"stories-pdf"] = proc do |r|
109
+ begin
110
+ Stories::Runner::PDF
111
+ rescue NameError
112
+ require File.expand_path(File.dirname(__FILE__) + "/runner/pdf")
113
+ Stories::Runner::PDF
114
+ end
115
+ end
116
+
117
+ # Common Webrat steps.
118
+ module Stories::Webrat
119
+ report :click_link do |name|
120
+ "Click #{name.inspect}"
121
+ end
122
+
123
+ report :click_button do |name|
124
+ "Click #{name.inspect}"
125
+ end
126
+
127
+ report :fill_in do |name, opts|
128
+ "Fill in #{name.inspect} with #{opts[:with].inspect}"
129
+ end
130
+
131
+ report :visit do |page|
132
+ "Go to #{page.inspect}"
133
+ end
134
+
135
+ report :check do |name|
136
+ "Check #{name.inspect}"
137
+ end
138
+
139
+ report :assert_contain do |text|
140
+ "I should see #{text.inspect}"
141
+ end
142
+ end
data/lib/stories.rb CHANGED
@@ -2,30 +2,16 @@ require "rubygems"
2
2
  require "contest"
3
3
 
4
4
  class Test::Unit::TestCase
5
- @@stories = []
6
-
7
5
  class << self
6
+ alias story context
8
7
  alias scenario test
9
-
10
- def story(name, &block)
11
- @@stories << name
12
- context(name, &block)
13
- end
14
-
15
- def stories
16
- @@stories
17
- end
18
8
  end
19
9
  end
20
10
 
21
- at_exit do
22
- unless Test::Unit::TestCase.stories.empty?
23
- puts
24
-
25
- Test::Unit::TestCase.stories.each do |s|
26
- puts "- #{s}"
27
- end
11
+ Test::Unit::AutoRunner::RUNNERS[:stories] = proc do |r|
12
+ puts "Story runner not found. You need to require 'stories/runner'."
13
+ end
28
14
 
29
- puts
30
- end
15
+ Test::Unit::AutoRunner::RUNNERS[:"stories-pdf"] = proc do |r|
16
+ puts "Story runner not found. You need to require 'stories/runner'."
31
17
  end
data/rails/init.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  if RAILS_ENV == 'test'
2
2
 
3
+ require File.dirname(__FILE__) + "/../lib/stories/runner"
4
+
3
5
  # Require webrat and configure it to work in Rails mode.
4
6
  require "webrat"
5
7
 
6
8
  Webrat.configure do |config|
7
9
  config.mode = :rails
8
10
  end
11
+
12
+ ActionController::IntegrationTest.send(:include, Stories::Webrat)
9
13
  end
data/test/all_test.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require File.dirname(__FILE__) + "/../lib/stories"
2
+ require File.dirname(__FILE__) + "/../lib/stories/runner"
3
+
4
+ # Use the story runner by default.
5
+ Test::Unit::AutoRunner::RUNNERS[:console] = Proc.new {|r| Stories::Runner }
2
6
 
3
7
  class UserStoryTest < Test::Unit::TestCase
4
8
  story "As a user I want to create stories so I can test if they pass" do
data/test/pdf_test.rb ADDED
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + "/../lib/stories"
2
+ require File.dirname(__FILE__) + "/../lib/stories/runner"
3
+ require File.dirname(__FILE__) + "/../lib/stories/runner/pdf"
4
+
5
+ class Stories::Runner::PDF
6
+ def render_header(pdf)
7
+ pdf.text "My custom header", :size => 20, :style => :bold
8
+ pdf.move_down 20
9
+ end
10
+ end
11
+
12
+ # Use the story runner by default.
13
+ Test::Unit::AutoRunner::RUNNERS[:console] = Proc.new {|r| Stories::Runner::PDF }
14
+
15
+ class UserStoryTest < Test::Unit::TestCase
16
+ story "As a user I want to create stories so I can test if they pass" do
17
+ setup do
18
+ @user = "valid user"
19
+ end
20
+
21
+ scenario "A valid user" do
22
+ assert_equal "valid user", @user
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citrusbyte-stories
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski
@@ -32,12 +32,15 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
 
34
34
  files:
35
+ - lib/stories/runner/pdf.rb
36
+ - lib/stories/runner.rb
35
37
  - lib/stories.rb
36
38
  - README.markdown
37
39
  - LICENSE
38
40
  - Rakefile
39
41
  - rails/init.rb
40
42
  - test/all_test.rb
43
+ - test/pdf_test.rb
41
44
  has_rdoc: false
42
45
  homepage: http://github.com/citrusbyte/stories
43
46
  post_install_message: