behaviors 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  Manifest.txt
2
2
  Rakefile
3
3
  lib/behaviors.rb
4
+ lib/behaviors/reporttask.rb
4
5
  test/behaviors_tasks_test.rb
5
6
  test/behaviors_test.rb
6
7
  test/tasks_test/lib/user.rb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake'
2
2
  require 'rubygems'
3
3
  require 'hoe'
4
4
 
5
- Hoe.new('behaviors','1.0.1') do |p|
5
+ Hoe.new('behaviors','1.0.2') do |p|
6
6
  p.author = "Atomic Object LLC"
7
7
  p.email = "dev@atomicobject.com"
8
8
  p.url = "http://behaviors.rubyforge.org"
@@ -0,0 +1,158 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Behaviors
5
+ include Rake
6
+
7
+ class ReportTask < TaskLib
8
+ attr_accessor :pattern
9
+ attr_accessor :html_dir
10
+
11
+ def initialize(name=:behaviors)
12
+ @name = name
13
+ @html_dir = 'doc'
14
+ yield self if block_given?
15
+ define
16
+ end
17
+
18
+ def define
19
+ desc "List behavioral definitions for the classes specified (use for=<regexp> to further limit files included in report)"
20
+ task @name do
21
+ specifications.each do |spec|
22
+ puts "#{spec.name} should:\n"
23
+ spec.requirements.each do |req|
24
+ puts " - #{req}"
25
+ end
26
+ end
27
+ end
28
+
29
+ desc "Generate html report of behavioral definitions for the classes specified (use for=<regexp> to further limit files included in report)"
30
+ task "#{@name}_html" do
31
+ require 'erb'
32
+ txt =<<-EOS
33
+ <html>
34
+ <head>
35
+ <style>
36
+
37
+ div.title
38
+ {
39
+ width: 600px;
40
+ font: bold 14pt trebuchet ms;
41
+ }
42
+
43
+ div.specification
44
+ {
45
+ font: bold 12pt trebuchet ms;
46
+ border: solid 1px black;
47
+ width: 600px;
48
+ padding: 5px;
49
+ margin: 5px;
50
+ }
51
+
52
+ ul.requirements
53
+ {
54
+ font: normal 11pt verdana;
55
+ padding-left: 0;
56
+ margin-left: 0;
57
+ border-bottom: 1px solid gray;
58
+ width: 600px;
59
+ }
60
+
61
+ ul.requirements li
62
+ {
63
+ list-style: none;
64
+ margin: 0;
65
+ padding: 0.25em;
66
+ border-top: 1px solid gray;
67
+ }
68
+ </style>
69
+ </head>
70
+ <body>
71
+ <div class="title">Specifications</div>
72
+ <% specifications.each do |spec| %>
73
+ <div class="specification">
74
+ <%= spec.name %> should:
75
+ <ul class="requirements">
76
+ <% spec.requirements.each do |req| %>
77
+ <li><%= req %></li>
78
+ <% end %>
79
+ </ul>
80
+ </div>
81
+ <% end %>
82
+ </body>
83
+ </html>
84
+ EOS
85
+ output_dir = File.expand_path(@html_dir)
86
+ mkdir_p output_dir
87
+ output_filename = output_dir + "/behaviors.html"
88
+ File.open(output_filename,"w") do |f|
89
+ f.write ERB.new(txt).result(binding)
90
+ end
91
+ puts "(Wrote #{output_filename})"
92
+ end
93
+ end
94
+
95
+ private
96
+ def test_files
97
+ test_list = FileList[@pattern]
98
+ if ENV['for']
99
+ test_list = test_list.grep(/#{ENV['for']}/i)
100
+ end
101
+ test_list
102
+ end
103
+
104
+ def specifications
105
+ test_files.map do |file|
106
+ spec = OpenStruct.new
107
+ m = %r".*/([^/].*)_test.rb".match(file)
108
+ class_name = titleize(m[1]) if m[1]
109
+ spec.name = class_name
110
+ spec.requirements = []
111
+ File::readlines(file).each do |line|
112
+ if line =~ /^\s*should\s+\(?\s*["'](.*)["']/
113
+ spec.requirements << $1
114
+ end
115
+ end
116
+ spec
117
+ end
118
+ end
119
+
120
+ ############################################################
121
+ # STOLEN FROM inflector.rb
122
+ ############################################################
123
+ #--
124
+ # Copyright (c) 2005 David Heinemeier Hansson
125
+ #
126
+ # Permission is hereby granted, free of charge, to any person obtaining
127
+ # a copy of this software and associated documentation files (the
128
+ # "Software"), to deal in the Software without restriction, including
129
+ # without limitation the rights to use, copy, modify, merge, publish,
130
+ # distribute, sublicense, and/or sell copies of the Software, and to
131
+ # permit persons to whom the Software is furnished to do so, subject to
132
+ # the following conditions:
133
+ #
134
+ # The above copyright notice and this permission notice shall be
135
+ # included in all copies or substantial portions of the Software.
136
+ #
137
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
138
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
139
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
140
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
141
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
142
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
143
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
144
+ #++
145
+ def titleize(word)
146
+ humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
147
+ end
148
+
149
+ def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/').
150
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
151
+ end
152
+
153
+ def humanize(lower_case_and_underscored_word)
154
+ lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
155
+ end
156
+
157
+ end
158
+ end
metadata CHANGED
@@ -1,9 +1,9 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: behaviors
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
6
+ version: 1.0.2
7
7
  date: 2007-01-13 00:00:00 -05:00
8
8
  summary: behavior-driven unit test helper
9
9
  require_paths:
@@ -25,12 +25,14 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Atomic Object LLC
30
31
  files:
31
32
  - Manifest.txt
32
33
  - Rakefile
33
34
  - lib/behaviors.rb
35
+ - lib/behaviors/reporttask.rb
34
36
  - test/behaviors_tasks_test.rb
35
37
  - test/behaviors_test.rb
36
38
  - test/tasks_test/lib/user.rb