specdown 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,5 +1,13 @@
1
1
  ## CHANGELOG
2
2
 
3
+ ## 0.1.3
4
+
5
+ The `specdown` command now accepts two options: -h and -r.
6
+
7
+ Usage: specdown [file1 [file2 [file3....]]]
8
+ -r, --root SPECDOWN_DIR defaults to ./specdown
9
+ -h, --help Display this screen
10
+
3
11
  ## 0.1.2
4
12
 
5
13
  New feature added: test hooks. (see the README)
data/README.markdown CHANGED
@@ -168,23 +168,29 @@ You can create test hooks that run before, after, and around tests. You can crea
168
168
 
169
169
  To create a global before hook, use the `Specdown.before` method:
170
170
 
171
- Specdown.before do
172
- puts "I run before every single test!"
173
- end
171
+ ```ruby
172
+ Specdown.before do
173
+ puts "I run before every single test!"
174
+ end
175
+ ```
174
176
 
175
177
  That before hook will - you guessed it - RUN BEFORE EVERY SINGLE TEST.
176
178
 
177
179
  Similary, you can run some code after every single test via the `Specdown.after` method:
178
180
 
179
- Specdown.after do
180
- puts "I run after every single test!"
181
- end
181
+ ```ruby
182
+ Specdown.after do
183
+ puts "I run after every single test!"
184
+ end
185
+ ```
182
186
 
183
187
  Whenever you need some code to run before _and_ after every single test, use the `Specdown.around` method:
184
188
 
185
- Specdown.around do
186
- puts "I run before _AND_ after every single test!"
187
- end
189
+ ```ruby
190
+ Specdown.around do
191
+ puts "I run before _AND_ after every single test!"
192
+ end
193
+ ```
188
194
 
189
195
  ### Scoping your hooks to specific markdown files
190
196
 
@@ -192,18 +198,19 @@ You might, at times, want hooks to run only for certain files.
192
198
 
193
199
  You can pass filenames (or regular expressions) to the `Specdown.before`, `Specdown.after`, and `Specdown.around` methods. The hooks will then execute whenever you execute any markdown file with matching filenames.
194
200
 
195
- Specdown.before "somefile.markdown", /^.*\.database.markdown$/ do
196
- puts "This runs before every test within 'somefile.markdown', and
197
- before every test in any markdown file whose filename ends
198
- with '.database.markdown'"
199
- end
200
-
201
+ ```ruby
202
+ Specdown.before "somefile.markdown", /^.*\.database.markdown$/ do
203
+ puts "This runs before every test within 'somefile.markdown', and
204
+ before every test in any markdown file whose filename ends
205
+ with '.database.markdown'"
206
+ end
207
+ ```
201
208
 
202
209
  ## TODO
203
210
 
204
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:
205
212
 
206
- * Run a single test
213
+ * Choose which files to run
207
214
  * color code the terminal output
208
215
  * offer the option of outputing the actual markdown while it executes, instead of "..F....FF......"
209
216
  * Better stack traces / reporting
data/bin/specdown CHANGED
@@ -1,8 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'specdown'
3
3
 
4
- Dir["./specdown/**/*.rb"].each do |ruby_file|
5
- load ruby_file
6
- end
7
-
8
4
  Specdown::Command.new.execute
@@ -1,3 +1,4 @@
1
+ puts "hooks loading!"
1
2
  Specdown.around /fun/ do
2
3
  puts "I run before and after fun tests."
3
4
  end
@@ -0,0 +1,26 @@
1
+ module Specdown
2
+ module OptionParser
3
+ extend self
4
+
5
+ def parse!
6
+ parser.parse!
7
+ Specdown::Config.tests = ARGV
8
+ end
9
+
10
+ private
11
+ def parser
12
+ ::OptionParser.new do |opts|
13
+ opts.banner = "Usage: specdown [file1 [file2 [file3....]]]"
14
+
15
+ opts.on '-r', '--root SPECDOWN_DIR', 'defaults to ./specdown' do |root|
16
+ Specdown::Config.root = root
17
+ end
18
+
19
+ opts.on '-h', '--help', 'Display this screen' do
20
+ puts opts
21
+ exit
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,17 +1,25 @@
1
1
  module Specdown
2
2
  class Command
3
- def initialize
4
- @markdowns = Dir["specdown/**/*.markdown"]
5
- end
6
-
7
3
  def execute
4
+ parse_options
5
+ load_test_environment
8
6
  run
9
- Specdown::EventServer.event :command_complete, @results
10
7
  end
11
8
 
12
9
  private
10
+ def parse_options
11
+ Specdown::OptionParser.parse!
12
+ end
13
+
14
+ def load_test_environment
15
+ Specdown::Config.test_environment_files.each do |file|
16
+ Kernel.load file
17
+ end
18
+ end
19
+
13
20
  def run
14
- @results = @markdowns.map {|markdown| Runner.new(markdown).run.stats}
21
+ @results = Specdown::Config.tests.map {|markdown| Runner.new(markdown).run.stats}
22
+ Specdown::EventServer.event :command_complete, @results
15
23
  end
16
24
  end
17
25
  end
@@ -3,6 +3,39 @@ module Specdown
3
3
  extend self
4
4
 
5
5
  attr_accessor :expectations
6
+ attr_accessor :tests
7
+ attr_accessor :root
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
18
+ end
19
+
20
+ def root
21
+ @root ||= "specdown"
22
+ end
23
+
24
+ def root=(new_root)
25
+ if new_root[-1..-1] == "/"
26
+ @root = new_root[0...-1]
27
+ else
28
+ @root = new_root
29
+ end
30
+ end
31
+
32
+ def tests
33
+ @tests ||= Dir["#{root}/**/*.markdown"] + Dir["#{root}/**/*.md"]
34
+ end
35
+
36
+ def tests=(test_files)
37
+ @tests = test_files unless test_files.empty?
38
+ end
6
39
 
7
40
  def reset!
8
41
  self.expectations = nil
data/lib/specdown.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'kramdown'
2
+ require 'optparse'
2
3
  require 'specdown/parser'
3
4
  require 'specdown/node'
4
5
  require 'specdown/tree'
@@ -19,3 +20,4 @@ require 'specdown/specdown'
19
20
  require 'specdown/sandbox_factory'
20
21
  require 'specdown/hooks'
21
22
  require 'specdown/hook'
23
+ require 'specdown/command/option_parser'
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -71,6 +71,7 @@ extra_rdoc_files:
71
71
  - CHANGELOG.markdown
72
72
  - README.markdown
73
73
  files:
74
+ - lib/specdown/command/option_parser.rb
74
75
  - lib/specdown/command.rb
75
76
  - lib/specdown/config.rb
76
77
  - lib/specdown/event_handlers/after_test.rb