specdown 0.3.0 → 0.4.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG.markdown +7 -0
  2. data/README.markdown +84 -8
  3. data/VERSION +1 -1
  4. data/features/command.feature +3 -1
  5. data/features/config.feature +3 -3
  6. data/features/fixtures/codeblocks_and_implicits.markdown +7 -0
  7. data/features/implicit_parser.feature +113 -0
  8. data/features/implicit_specs.feature +135 -0
  9. data/features/parser.feature +69 -1
  10. data/features/pending_specs.feature +49 -0
  11. data/features/report_summary.feature +1 -1
  12. data/features/specdown_examples/complete_implicit/specdown/implicit.specdown +4 -0
  13. data/features/specdown_examples/complete_implicit/specdown/test.markdown +3 -0
  14. data/features/specdown_examples/no_implicit/specdown/test.markdown +3 -0
  15. data/features/specdown_examples/pending_implicit/specdown/implicit.specdown +4 -0
  16. data/features/specdown_examples/pending_implicit/specdown/test.markdown +3 -0
  17. data/features/specdown_examples/pending_specs/specdown/test.markdown +7 -0
  18. data/features/step_definitions/command.rb +7 -3
  19. data/features/step_definitions/implicit_parser.rb +19 -0
  20. data/features/step_definitions/implicit_specs.rb +18 -0
  21. data/features/step_definitions/parser.rb +24 -0
  22. data/features/step_definitions/pending_specs.rb +7 -0
  23. data/features/support/env.rb +6 -0
  24. data/lib/specdown.rb +6 -0
  25. data/lib/specdown/config.rb +12 -1
  26. data/lib/specdown/event_handlers/test_pending.rb +3 -0
  27. data/lib/specdown/event_handlers/test_undefined.rb +3 -0
  28. data/lib/specdown/implicit_parser.rb +47 -0
  29. data/lib/specdown/node.rb +2 -1
  30. data/lib/specdown/parser.rb +40 -6
  31. data/lib/specdown/pending.rb +7 -0
  32. data/lib/specdown/pending_exception.rb +4 -0
  33. data/lib/specdown/reporter.rb +8 -0
  34. data/lib/specdown/reporters/color_terminal_reporter.rb +12 -0
  35. data/lib/specdown/reporters/terminal_reporter.rb +16 -0
  36. data/lib/specdown/reporters/text_reporter.rb +8 -0
  37. data/lib/specdown/runner.rb +25 -16
  38. data/lib/specdown/runner/report_summary.rb +8 -0
  39. data/lib/specdown/runner/stats.rb +13 -2
  40. data/lib/specdown/sandbox_decorators/pending.rb +3 -0
  41. data/lib/specdown/templates/color_summary.erb +20 -4
  42. data/lib/specdown/templates/summary.erb +17 -0
  43. metadata +45 -9
data/CHANGELOG.markdown CHANGED
@@ -1,5 +1,12 @@
1
1
  ## CHANGELOG
2
2
 
3
+ ## 0.4.0.beta.1
4
+
5
+ First beta release with implicit specs support. See the "Implicit Specs"
6
+ section in the README for details!
7
+
8
+ Also, output format now defaults to "condensed".
9
+
3
10
  ## 0.3.0
4
11
 
5
12
  NOTICE: Non-backwards compatible release.
data/README.markdown CHANGED
@@ -166,10 +166,15 @@ raise "WTF?" unless 1 == 1
166
166
  raise "name in scope" if defined? name
167
167
  ```
168
168
 
169
- ## Non-executing code blocks
169
+ ## Non-executable code blocks
170
170
 
171
- It's likely that in the process of writing your documentation tests, you'll want
172
- to add some code into your markdown that you don't want executed.
171
+ As of version `0.3.0`, you must surround any codeblocks you
172
+ want specdown to execute with a github-flavored backtick fence. This
173
+ change is not backwards-compatible with previous versions; you'll need
174
+ to update your tests if you want to upgrade to this version.
175
+
176
+ I made this change because it's likely that in the process of writing your
177
+ specdown, you'll want to add some code into your markdown that you don't want executed.
173
178
  Perhaps it's code in a different language, or perhaps you're showing off
174
179
  some command line functionality.
175
180
 
@@ -177,7 +182,7 @@ Specdown only executes fenced codeblocks specifically flagged as `ruby`.
177
182
  Thus, if you want to add some code to your markdown that shouldn't be
178
183
  executed, then just don't specifically flag it as Ruby:
179
184
 
180
- # Non-Executing Code Blocks Example
185
+ # Non-Executable Code Blocks
181
186
 
182
187
  Here's an example of a non-executing code block:
183
188
 
@@ -195,7 +200,7 @@ executed, then just don't specifically flag it as Ruby:
195
200
  I'm not flagged as anything, so I won't execute.
196
201
  ```
197
202
 
198
- ## Executing codeblocks
203
+ ## Executable codeblocks
199
204
 
200
205
  The only way to make a code block execute is to specifically flag it as Ruby
201
206
 
@@ -203,6 +208,73 @@ executed, then just don't specifically flag it as Ruby:
203
208
  puts "I execute!"
204
209
  ```
205
210
 
211
+ ## Implicit Specs
212
+
213
+ In all of the examples so far, we've made all code that we want executed
214
+ explicit within the markdown. Sometimes, however, it's advantageous to
215
+ simply state a specification, and then map that to code
216
+ behind-the-scenes. They're conceptually equivalent to cucumber step
217
+ definitions.
218
+
219
+ Imagine we've written the following markdown for an imaginary `Article`
220
+ model:
221
+
222
+ # Deleting an article from the database
223
+
224
+ Imagine we create the following article:
225
+
226
+ ```ruby
227
+ article = Article.create :title => "Specdown"
228
+ ```
229
+
230
+ We can delete the article by simply using the `delete!` method:
231
+
232
+ ```ruby
233
+ article.delete!
234
+ ```
235
+
236
+ **The article should now be deleted from the database.**
237
+
238
+ Notice the emphasis around the last sentence. If we execute this with
239
+ `specdown`, we'll recieve the following result:
240
+
241
+ $ specdown
242
+
243
+ 1 markdown
244
+ 1 test
245
+ 0 passing
246
+ 0 failing
247
+ 1 undefined
248
+
249
+
250
+ Now add the following implicit spec definition to a file suffixed with ".specdown":
251
+
252
+ The article should now be deleted from the database.
253
+ ----------------------------------------------------
254
+
255
+ pending # replace this with the code you want
256
+
257
+ If we do as it says and rerun the `specdown` command, we'll receive a
258
+ notice that we now have a pending implicit spec. Thus, we could
259
+ implement the pending spec like so (assuming we were using RSpec
260
+ expectations):
261
+
262
+ ```markdown
263
+ The article should now be deleted from the database.
264
+ ----------------------------------------------------
265
+
266
+ Article.all.should be_empty
267
+ ```
268
+
269
+ The ".specdown" file is simply a markdown file with a different
270
+ extension. It should consist of an unordered list of spec / definition pairs.
271
+
272
+ Note that we didn't surround our code with a github-flavored backtick
273
+ fence. Since ".specdown" files are solely used for defining implicit
274
+ specifications, it's assumed that all code blocks (unless they're
275
+ spefically marked as something other than ruby) will be executed.
276
+
277
+
206
278
  ## Setting up your test environment
207
279
 
208
280
  Similar to the cucumber testing framework: if you put a ruby file somewhere inside your "specdown" directory, `specdown` will find it and load it.
@@ -341,15 +413,19 @@ You can also configure this in your env.rb by setting
341
413
  `Specdown::Config.format` to either `:short` or `:condensed`:
342
414
 
343
415
  ```ruby
344
- Specdown::Config.format = :condensed
416
+ Specdown::Config.format = :short
345
417
  ```
346
418
 
347
- The default is `:short`.
419
+ The default is `:condensed`.
348
420
 
349
421
  ## TODO
350
422
 
351
- This library is still very new, but I am rapidly adding features to it. Here's what is on the immediate horizon:
423
+ This library is quite new, but I am rapidly adding features to it. Here's what is on the immediate horizon:
352
424
 
353
425
  * allow flagged text in the markdown to execute code, like a cucumber step definition
354
426
  * offer the option of outputing the actual markdown while it executes, instead of "..F....FF......"
355
427
  * Better stack traces / reporting
428
+
429
+ ## LICENSE
430
+
431
+ This software is [public domain](http://en.wikipedia.org/wiki/Public_domain). GO WILD
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0.beta.1
@@ -113,7 +113,9 @@ Feature: `specdown` command
113
113
  When I run `specdown specdown/tests`
114
114
  Then I should see the following output:
115
115
  """
116
- ...
116
+ 1.markdown: .
117
+ 2.markdown: .
118
+ 3.markdown: .
117
119
 
118
120
  3 markdowns
119
121
  3 tests
@@ -50,7 +50,7 @@ Feature: Specdown::Config
50
50
  * Specdown::Config.expectations #==> nil
51
51
  * Specdown::Config.reporter #==> Specdown::ColorTerminalReporter
52
52
  * Specdown::Config.root #==> "specdown"
53
- * Specdown::Config.format #==> :short
53
+ * Specdown::Config.format #==> :condensed
54
54
 
55
55
  Scenario: Reset the Specdown::Config
56
56
  Given I have configured Specdown:
@@ -58,7 +58,7 @@ Feature: Specdown::Config
58
58
  Specdown::Config.expectations = :rspec
59
59
  Specdown::Config.reporter = Specdown::TerminalReporter
60
60
  Specdown::Config.root = "dir/"
61
- Specdown::Config.format = :condensed
61
+ Specdown::Config.format = :short
62
62
  """
63
63
 
64
64
  When I reset Specdown:
@@ -70,7 +70,7 @@ Feature: Specdown::Config
70
70
  * Specdown::Config.expectations #==> nil
71
71
  * Specdown::Config.reporter #==> Specdown::ColorTerminalReporter
72
72
  * Specdown::Config.root #==> "specdown"
73
- * Specdown::Config.format #==> :short
73
+ * Specdown::Config.format #==> :condensed
74
74
 
75
75
 
76
76
 
@@ -0,0 +1,7 @@
1
+ # Specdown Example
2
+
3
+ **This is an implicit spec.**
4
+
5
+ ```ruby
6
+ hi = "explicit spec"
7
+ ```
@@ -0,0 +1,113 @@
1
+ Feature: Specdown::ImplicitParser
2
+
3
+ The Specdown::ImplicitParser will parse ".specdown" files.
4
+
5
+ Imagine the following file "implicits.specdown":
6
+
7
+
8
+ some text
9
+ ==================
10
+
11
+ some code
12
+
13
+
14
+
15
+ some more text
16
+ ==================
17
+
18
+ some more code
19
+
20
+
21
+ We can pass it off to the Specdown::ImplicitParser as a string:
22
+
23
+ result = Specdown::ImplicitParser File.read("implicits.specdown")
24
+
25
+ The result will be a hash lookup for the definitions:
26
+
27
+ result.should == {
28
+ "some text" => "some code",
29
+ "some more text" => "some more code"
30
+ }
31
+
32
+
33
+ Note that, unlike a regular markdown file that you ask specdown to execute, specdown does not care about the header levels inside your ".specdown" files.
34
+
35
+
36
+ Scenario: Multiple Implicits
37
+
38
+ Given the following implicit specification:
39
+ """
40
+ @implicits = <<-SPECDOWN.undent
41
+ a
42
+ -----------------
43
+
44
+ a code
45
+
46
+
47
+ b
48
+ ===================
49
+
50
+ b code
51
+
52
+
53
+ c
54
+ ------------------
55
+
56
+ here's the c code:
57
+
58
+ c code
59
+
60
+ plus some more c code:
61
+
62
+ more c code
63
+
64
+ SPECDOWN
65
+ """
66
+
67
+ When I parse it with the implicit parser:
68
+ """
69
+ @result = Specdown::ImplicitParser.parse @implicits
70
+ """
71
+
72
+ Then I should receive a hash lookup of implicit definitions:
73
+ """
74
+ @result.should == {
75
+ "a" => "a code",
76
+ "b" => "b code",
77
+ "c" => "c code\nmore c code"
78
+ }
79
+ """
80
+
81
+ Scenario: Several implicit specification strings
82
+
83
+ Given two implicit specification strings:
84
+ """
85
+ @implicits_1 = <<-SPECDOWN.undent
86
+ a
87
+ ---------------
88
+
89
+ a code
90
+ SPECDOWN
91
+
92
+ @implicits_2 = <<-SPECDOWN.undent
93
+ b
94
+ --------------
95
+
96
+ ```ruby
97
+ b code
98
+ ```
99
+ SPECDOWN
100
+ """
101
+
102
+ When I pass both off to the Specdown::ImplicitParser:
103
+ """
104
+ @results = Specdown::ImplicitParser.parse @implicits_1, @implicits_2
105
+ """
106
+
107
+ Then I should receive a hash lookup of implicit definitions:
108
+ """
109
+ @results.should == {
110
+ "a" => "a code",
111
+ "b" => "b code"
112
+ }
113
+ """
@@ -0,0 +1,135 @@
1
+ Feature: Implicit Specs
2
+
3
+ In all of the examples so far, we've made all code that we want executed
4
+ explicit within the markdown. Sometimes, however, it's advantageous to
5
+ simply state a specification, and then map that to code
6
+ behind-the-scenes. They're conceptually equivalent to cucumber step
7
+ definitions.
8
+
9
+ Imagine we've written the following markdown for an imaginary `Article`
10
+ model:
11
+
12
+ \# Deleting an article from the database
13
+
14
+ Imagine we create the following article:
15
+
16
+ ```ruby
17
+ article = Article.create :title => "Specdown"
18
+ ```
19
+
20
+ We can delete the article by simply using the `delete!` method:
21
+
22
+ ```ruby
23
+ article.delete!
24
+ ```
25
+
26
+ **The article should now be deleted from the database.**
27
+
28
+ Notice the emphasis around the last sentence. If we execute this with
29
+ `specdown`, we'll recieve the following result:
30
+
31
+ ```sh
32
+ $ specdown
33
+
34
+ 1 markdown
35
+ 1 test
36
+ 0 passing
37
+ 0 failing
38
+ 1 undefined
39
+
40
+
41
+ Now add the following implicit spec definition to a file suffixed with ".specdown":
42
+
43
+ The article should now be deleted from the database.
44
+ ------------------------------------------------------
45
+
46
+ pending # replace this with the code you want
47
+ ```
48
+
49
+ If we do as it says and rerun the `specdown` command, we'll receive a
50
+ notice that we now have a pending implicit spec. Thus, we could
51
+ implement the pending spec like so (assuming we were using RSpec
52
+ expectations):
53
+
54
+ ```markdown
55
+ The article should now be deleted from the database.
56
+ --------------------------------------------------------
57
+
58
+ Article.all.should be_empty
59
+ ```
60
+
61
+ The ".specdown" file is simply a markdown file with a different
62
+ extension. It should consist of an unordered list of spec / definition pairs.
63
+
64
+ Note that, according to the [markdown specification](http://daringfireball.net/projects/markdown/syntax#list), codeblocks within list items must be indented twice (two tabs or 8 spaces).
65
+
66
+
67
+ Scenario: No implicit specification
68
+
69
+ Given a markdown file with an implicit spec:
70
+ """
71
+ # Heading
72
+
73
+ **An implicit spec.**
74
+ """
75
+ But no implicit specification
76
+ When I run the `specdown` command
77
+ Then I should see the following output:
78
+ """
79
+ 1 undefined
80
+
81
+ Now add the following implicit spec definition to a file suffixed with ".specdown":
82
+
83
+ An implicit spec.
84
+ ------------------------------------------------------
85
+
86
+ pending # replace this with the code you wish you had
87
+ """
88
+
89
+ Scenario: Pending implicit specification
90
+ Given a markdown file with an implicit spec:
91
+ """
92
+ # Heading
93
+
94
+ **An implicit spec.**
95
+ """
96
+
97
+ And a specdown file with a pending specification:
98
+ """
99
+ An implicit spec.
100
+ ---------------------
101
+
102
+ pending
103
+ """
104
+
105
+ When I run the `specdown` command
106
+ Then I should see the following output:
107
+ """
108
+ 1 pending
109
+ """
110
+
111
+ Scenario: Complete implicit specification
112
+ Given a markdown file with an implicit spec:
113
+ """
114
+ # Heading
115
+
116
+ **An implicit spec.**
117
+ """
118
+
119
+ And a specdown file with a complete specification:
120
+ """
121
+ An implicit spec.
122
+ ----------------------
123
+
124
+ raise "oops!" unless 1 == 1
125
+ """
126
+
127
+ When I run the `specdown` command
128
+
129
+ Then I should see the following output:
130
+ """
131
+ 1 success
132
+ 0 failures
133
+ """
134
+
135
+