specdown 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,6 +1,12 @@
1
1
  ## CHANGELOG
2
2
 
3
- ## 0.1.3
3
+ ## 0.1.4
4
+
5
+ The `specdown` command now allows you to pass off directories of tests as well as individual tests.
6
+
7
+ specdown specdown/subdir/ specdown/test1.md specdown/subdir2/*.markdown
8
+
9
+ ## 0.1.3 (2012/01/02)
4
10
 
5
11
  The `specdown` command now accepts two options: -h and -r.
6
12
 
@@ -8,7 +14,7 @@ The `specdown` command now accepts two options: -h and -r.
8
14
  -r, --root SPECDOWN_DIR defaults to ./specdown
9
15
  -h, --help Display this screen
10
16
 
11
- ## 0.1.2
17
+ ## 0.1.2 (2012/01/02)
12
18
 
13
19
  New feature added: test hooks. (see the README)
14
20
 
data/README.markdown CHANGED
@@ -10,7 +10,7 @@ If you don't know what README DRIVEN DEVELOPMENT IS, checkout Tom Preston Werner
10
10
 
11
11
  ## CAVEAT
12
12
 
13
- This library has just been released. It has only a few features, but expect those to grow rapidly over the coming weeks. Follow this repo to stay up to date on the latest changes, or better yet, fork and implement some needed features (see the TODO list at the end of this README).
13
+ This library is very new. It has only a few features, but it's growing rapidly. Follow this repo to stay up to date on the latest changes, or better yet, fork and implement some needed features (see the TODO list at the end of this README).
14
14
 
15
15
  ## Installation
16
16
 
@@ -206,11 +206,29 @@ Specdown.before "somefile.markdown", /^.*\.database.markdown$/ do
206
206
  end
207
207
  ```
208
208
 
209
+ ## specdown command line
210
+
211
+ You can run `specdown -h` at the command line to get USAGE and options.
212
+
213
+ If you run `specdown` without any arguments, specdown will look for a "specdown" directory inside your current working directory, then search for any markdown files inside of it, and also load any ruby files inside of it.
214
+
215
+ If you want to run just a single file or a set of files, or a directory of files, simply pass them on the command line:
216
+
217
+ ```sh
218
+ $ specdown specdown/test.markdown
219
+ $ specdown specdown/unit_tests
220
+ ```
221
+
222
+ You can use the `-r` flag to specify the root of the specdown directory (it defaults to "specdown/").
223
+
224
+ ```sh
225
+ $ specdown test.markdown -r specdown_environment/
226
+ ```
227
+
209
228
  ## TODO
210
229
 
211
- This library is the result of just a couple of days worth of work. It's a basic minimum viable product, but there are tons of features I want to implement. Here's what's on my immediate horizon:
230
+ This library is still very new, but we are rapidly adding features to it. Here's what is on the immediate horizon:
212
231
 
213
- * Choose which files to run
214
232
  * color code the terminal output
215
233
  * offer the option of outputing the actual markdown while it executes, instead of "..F....FF......"
216
234
  * Better stack traces / reporting
data/bin/specdown CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'specdown'
3
-
3
+ STDOUT.sync = true
4
4
  Specdown::Command.new.execute
@@ -94,3 +94,17 @@ Feature: `specdown` command
94
94
  In parser_example.markdown: <NoMethodError> undefined method `be'
95
95
  In parser_example.markdown: <NoMethodError> undefined method `satisfy'
96
96
  """
97
+
98
+
99
+ @focus
100
+ Scenario: `specdown` command invoked with a directory
101
+ Given I have a specdown directory 'specdown/tests' containing 3 markdown files, each with 1 passing test
102
+ When I run `specdown specdown/tests`
103
+ Then I should see the following output:
104
+ """
105
+ ...
106
+
107
+ 3 markdowns
108
+ 3 tests
109
+ 0 failures
110
+ """
@@ -1,16 +1,40 @@
1
1
  Feature: Report
2
2
 
3
- Specdown comes with a generic reporting class. If you provide it with a runner's Specdown::Stats object (or an array of Specdown::Stats objects), then it will generate a report for you.
3
+ Specdown comes with a generic reporting class. If you provide it with a runner (or an array of runners), then it will generate a report for you.
4
4
 
5
- For example, suppose we have the following Specdown::Stats instance:
5
+
6
+ For example, suppose we have the following markdown file:
7
+
8
+ \# Specdown Example
9
+
10
+ This is an example specdown file.
11
+
12
+ \## Child Node
13
+
14
+ This section is a child node. It contains some ruby code:
15
+
16
+ "simple code".should_not == nil
17
+
18
+ \### First Leaf
19
+
20
+ This section has a failure simulation:
21
+
22
+ raise "specdown error simulation!"
23
+
24
+ \## Last Leaf
6
25
 
7
- stats = Specdown::Stats.new
8
- stats.tests = 3
9
- stats.exceptions = [StandardError.new("error simulation")]
26
+ This section is a leaf node. It contains some ruby code:
27
+
28
+ 1.should == 1
29
+
30
+ If we create a Specdown::Runner instance from it and run it:
31
+
32
+ runner = Specdown::Runner.new("/features/fixtures/parser_example.markdown")
33
+ runner.run
10
34
 
11
35
  We could then pass it off to our reporter class and receive the following report:
12
36
 
13
- Specdown::Report.new(stats).generate.should == %{
37
+ Specdown::Report.new(runner).generate.should == %{
14
38
  1 markdown
15
39
  3 tests
16
40
  2 successes
@@ -21,37 +45,46 @@ Feature: Report
21
45
 
22
46
 
23
47
  Scenario: A Specdown::Report instantiated with a single stats object
24
-
25
- Given the following Specdown::Stats instance:
26
- """
27
- @stats = Specdown::Stats.new
28
- @stats.tests = 3
29
- @stats.exceptions << StandardError.new("error simulation")
30
- """
31
48
 
32
- Then `Specdown::Report.new(@stats).generate` should include the following output:
49
+ Given the following specdown example file located at 'features/fixtures/parser_example.markdown':
33
50
  """
34
- 1 markdown
35
- 3 tests
36
- 1 failure
51
+ # Specdown Example
37
52
 
38
- error simulation
39
- """
53
+ This is an example specdown file.
40
54
 
41
- Scenario: A Specdown::Report instantiated with an array of stats
55
+ ## Child Node
42
56
 
43
- Given the following of Specdown::Stats instances:
44
- """
45
- @results = [
46
- Specdown::Stats.new.tap {|s| s.tests = 3 },
47
- Specdown::Stats.new.tap {|s| s.tests = 1; s.exceptions << StandardError.new("error simulation") }
48
- ]
57
+ This section is a child node. It contains some ruby code:
58
+
59
+ "simple code".should_not == nil
60
+
61
+ ### First Leaf
62
+
63
+ This section has a failure simulation:
64
+
65
+ raise "specdown error simulation!"
66
+
67
+ ## Last Leaf
68
+
69
+ This section is a leaf node. It contains some ruby code:
70
+
71
+ 1.should == 1
49
72
  """
50
73
 
51
- Then `Specdown::Report.new(@results).generate` should include the following output:
74
+ And the following runner:
52
75
  """
53
- 2 markdowns
54
- 4 tests
76
+ @runner = Specdown::Runner.new("features/fixtures/parser_example.markdown")
77
+ """
78
+
79
+ When I run the tests in the runner:
80
+ """
81
+ @runner.run
82
+ """
83
+
84
+ Then `Specdown::Report.new(@runner).generate` should include the following output:
85
+ """
86
+ 1 markdown
87
+ 2 tests
55
88
  1 failure
56
89
 
57
90
  error simulation
@@ -0,0 +1 @@
1
+ Specdown::Config.expectations = :test_unit
@@ -0,0 +1,3 @@
1
+ # Specdown Example
2
+
3
+ This is an example specdown file.
@@ -0,0 +1,3 @@
1
+ # Specdown Example
2
+
3
+ This is an example specdown file.
@@ -0,0 +1,3 @@
1
+ # Specdown Example
2
+
3
+ This is an example specdown file.
@@ -4,7 +4,7 @@ end
4
4
 
5
5
  Then /^I should see the following output:$/ do |string|
6
6
  string.split("\n").each do |line|
7
- @output.include?(line.strip).should be(true)
7
+ @output.should include(line.strip)
8
8
  end
9
9
  end
10
10
 
@@ -19,3 +19,11 @@ end
19
19
  Given /^a single ruby file:$/ do |string|
20
20
  @directory = "features/specdown_examples/with_ruby/"
21
21
  end
22
+
23
+ Given /^I have a specdown directory 'specdown\/tests' containing 3 markdown files, each with 1 passing test$/ do
24
+ @directory = "features/specdown_examples/nested_directories_test/"
25
+ end
26
+
27
+ When /^I run `(.*)`$/ do |command|
28
+ @output = `cd #{@directory} && bundle exec ruby -I ../../../lib ../../../bin/#{command}`
29
+ end
@@ -1,4 +1,8 @@
1
- Given /^the following Specdown::Stats instance:$/ do |string|
1
+ Given /^the following runner:$/ do |string|
2
+ eval string
3
+ end
4
+
5
+ When /^I run the tests in the runner:$/ do |string|
2
6
  eval string
3
7
  end
4
8
 
@@ -10,7 +10,7 @@ module Specdown
10
10
  private
11
11
  def parser
12
12
  ::OptionParser.new do |opts|
13
- opts.banner = "Usage: specdown [file1 [file2 [file3....]]]"
13
+ opts.banner = "Usage: specdown -h | specdown [FILE|DIR]+ [-r]"
14
14
 
15
15
  opts.on '-r', '--root SPECDOWN_DIR', 'defaults to ./specdown' do |root|
16
16
  Specdown::Config.root = root
@@ -18,8 +18,16 @@ module Specdown
18
18
  end
19
19
 
20
20
  def run
21
- @results = Specdown::Config.tests.map {|markdown| Runner.new(markdown).run.stats}
22
- Specdown::EventServer.event :command_complete, @results
21
+ @results = []
22
+
23
+ Kernel.at_exit do
24
+ Specdown::EventServer.event :command_complete, @results
25
+ end
26
+
27
+ Specdown::Config.tests.each do |markdown|
28
+ @results << Runner.new(markdown)
29
+ @results.last.run
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -6,39 +6,59 @@ module Specdown
6
6
  attr_accessor :tests
7
7
  attr_accessor :root
8
8
 
9
- def test_environment_files
10
- unless @test_environment_files
11
- @test_environment_files = Dir["#{root}/**/*.rb"]
12
- unless root[0..0] == "/"
13
- @test_environment_files.map! {|file| File.join Dir.pwd, file}
14
- end
15
- end
16
-
17
- @test_environment_files
9
+ def reset!
10
+ self.expectations = nil
18
11
  end
19
-
12
+
20
13
  def root
21
14
  @root ||= "specdown"
22
15
  end
23
16
 
24
17
  def root=(new_root)
25
- if new_root[-1..-1] == "/"
26
- @root = new_root[0...-1]
27
- else
28
- @root = new_root
29
- end
18
+ @root = strip_trailing_slash new_root
30
19
  end
31
20
 
32
21
  def tests
33
- @tests ||= Dir["#{root}/**/*.markdown"] + Dir["#{root}/**/*.md"]
22
+ @tests ||= find_tests_in root
34
23
  end
35
24
 
36
25
  def tests=(test_files)
37
- @tests = test_files unless test_files.empty?
26
+ unless test_files.empty?
27
+ @tests = test_files
28
+
29
+ @tests.map! do |test_dir|
30
+ if File.directory? test_dir
31
+ find_tests_in test_dir
32
+ else
33
+ test_dir
34
+ end
35
+ end.flatten!
36
+ end
38
37
  end
38
+
39
+ def test_environment_files
40
+ unless @test_environment_files
41
+ @test_environment_files = Dir["#{root}/**/*.rb"]
42
+ unless root[0..0] == "/"
43
+ @test_environment_files.map! {|file| File.join Dir.pwd, file}
44
+ end
45
+ end
39
46
 
40
- def reset!
41
- self.expectations = nil
47
+ @test_environment_files
48
+ end
49
+
50
+ private
51
+ def find_tests_in(directory)
52
+ directory = strip_trailing_slash directory
53
+ Dir["#{directory}/**/*.markdown"] + Dir["#{directory}/**/*.md"]
54
+ end
55
+
56
+ def strip_trailing_slash(string)
57
+ if string[-1..-1] == "/"
58
+ string[0...-1]
59
+ else
60
+ string
61
+ end
42
62
  end
43
63
  end
44
64
  end
@@ -1,11 +1,8 @@
1
1
  module Specdown
2
2
  class Report
3
- def initialize(stats)
4
- if stats.kind_of? Array
5
- @stats = stats
6
- else
7
- @stats = [stats]
8
- end
3
+ def initialize(runners)
4
+ runners = [runners] unless runners.respond_to?(:map)
5
+ @stats = runners.map &:stats
9
6
  end
10
7
 
11
8
  def generate
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specdown
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-02 00:00:00 Z
18
+ date: 2012-01-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: kramdown
@@ -113,6 +113,10 @@ files:
113
113
  - features/specdown_examples/before_hooks/specdown/env.rb
114
114
  - features/specdown_examples/before_hooks/specdown/hooks.rb
115
115
  - features/specdown_examples/before_hooks/specdown/parser_example.markdown
116
+ - features/specdown_examples/nested_directories_test/specdown/env.rb
117
+ - features/specdown_examples/nested_directories_test/specdown/tests/1.markdown
118
+ - features/specdown_examples/nested_directories_test/specdown/tests/2.markdown
119
+ - features/specdown_examples/nested_directories_test/specdown/tests/3.markdown
116
120
  - features/specdown_examples/no_ruby/specdown/parser_example.markdown
117
121
  - features/specdown_examples/scoped_hooks/specdown/env.rb
118
122
  - features/specdown_examples/scoped_hooks/specdown/hooks.rb
@@ -182,6 +186,10 @@ test_files:
182
186
  - features/specdown_examples/before_hooks/specdown/env.rb
183
187
  - features/specdown_examples/before_hooks/specdown/hooks.rb
184
188
  - features/specdown_examples/before_hooks/specdown/parser_example.markdown
189
+ - features/specdown_examples/nested_directories_test/specdown/env.rb
190
+ - features/specdown_examples/nested_directories_test/specdown/tests/1.markdown
191
+ - features/specdown_examples/nested_directories_test/specdown/tests/2.markdown
192
+ - features/specdown_examples/nested_directories_test/specdown/tests/3.markdown
185
193
  - features/specdown_examples/no_ruby/specdown/parser_example.markdown
186
194
  - features/specdown_examples/scoped_hooks/specdown/env.rb
187
195
  - features/specdown_examples/scoped_hooks/specdown/hooks.rb