Permalink
Browse files

got suites going ... need to pay some tech debt asap

  • Loading branch information...
1 parent f53b6cc commit 3690a872b703fc6194ba468452e72a1baac2d3e4 @msuarz msuarz committed Aug 27, 2012
Showing with 73 additions and 48 deletions.
  1. +1 −1 package.json
  2. +4 −4 src/frankendoc.coffee
  3. +16 −20 src/readers/confluence.coffee
  4. +28 −0 src/readers/docs.coffee
  5. +19 −18 src/readers/files.coffee
  6. +5 −5 src/reports/teamcity.coffee
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "frankendoc",
- "version": "0.2.2",
+ "version": "0.2.3",
"description" : "bringing documents alive",
"repository" : { "type" : "git", "url" : "https://github.com/limadelic/frankendoc.git" },
"keywords" : ["testing", "atdd", "bdd"],
View
8 src/frankendoc.coffee
@@ -18,10 +18,10 @@ class Frank
@report.start()
@read()
- console.log doc.name for doc in @files.docs
- #if doc.is_suite
- #then @report.suite doc
- #else @run_doc doc
+ for doc in @files.docs()
+ if doc.is_suite
+ then @report.suite doc
+ else @run_doc doc
@report.stop()
View
36 src/readers/confluence.coffee
@@ -1,42 +1,38 @@
rest = require 'restler'
-{ Doc } = require './doc'
+{ Docs } = require './docs'
class @Reader
read: ->
return unless @root?
@pending_docs = [ @root ]
while @pending_docs.length
- doc @pending_docs.shift()
+ doc = @pending_docs.shift()
if doc.is_suite
- @docs.push doc
- else
- @sync.read_doc doc
+ then @docs.add_suite doc.name
+ else @sync.read_doc doc
+ @docs
read_doc: (id, done) ->
uri = "#{@root_uri}/content/#{id}?expand=children"
- rest.get(uri, @options).on 'complete', (data) =>
- children = @children data
- @add_suite data if children.length
- @add_doc data
- @pending_docs.unshift children
+ rest.get(uri, @options).on 'complete', (@data) =>
+ @add_suite() if @has_children()
+ @add_doc()
+ @queue_children()
done()
- add_suite: (data) -> @pending_docs.unshift @docs.push
- name: data.title
- is_suite: true
+ add_suite: -> @pending_docs.unshift @docs.add_suite @data.title
- add_doc: (data) -> @docs.push
- name: data.title
- steps: @doc.read data.body.value
+ add_doc: -> @docs.add @data.title, @data.body.value
- children: (data) -> child.id for child in data.children.content
+ has_children: -> @data.children.content.length
+
+ queue_children: -> for child in @data.children.content
+ @pending_docs.unshift child.id
constructor: ->
- @docs = []
-
- @doc = new Doc
+ @docs = new Docs
line_break: '\n'
code_block: /ac:name="code".*?CDATA\[([\s\S]*?)\]\]><\//g
View
28 src/readers/docs.coffee
@@ -0,0 +1,28 @@
+{ Doc } = require './doc'
+_ = require 'underscore'
+
+class @Docs
+
+ constructor: (opt) ->
+ @docs = []
+ @doc = new Doc opt
+
+ add: (name, content) ->
+ @docs.push
+ name: name
+ steps: @doc.read content
+ @last()
+
+ add_suite: (name) ->
+ return if @removed_empty_suite(name)?
+
+ @docs.push
+ name: name
+ is_suite: true
+
+ @last()
+
+ removed_empty_suite: (name) ->
+ @docs.pop() if @last()?.is_suite and @last().name is name
+
+ last: -> _.last @docs
View
37 src/readers/files.coffee
@@ -2,35 +2,37 @@ fs = require 'fs'
path = require 'path'
{ Reader } = require './confluence'
-{ Doc } = require './doc'
+{ Docs } = require './docs'
class @Files
constructor: ->
- @docs = []
@code = []
- @doc = new Doc
+ @_docs = new Docs
+
+ docs: -> @_docs.docs
is_dir: -> fs.statSync(@file).isDirectory()
+ skip_dir: -> @file.match /node_modules$/
find_files: (dir, ext, add) ->
@add_suite dir
+
for file in fs.readdirSync dir
- @file = path.resolve dir, file
- if @is_dir()
- @find_files @file, ext, add unless file is 'node_modules'
- else if @file.match ext
- add()
+ @find_file path.resolve(dir, file), ext, add
+
@add_suite dir
+ find_file: (@file, ext, add) ->
+ if @is_dir()
+ then @find_files(@file, ext, add) unless @skip_dir()
+ else add() if @file.match(ext)
+
read: ->
@read_docs()
@read_code()
- use_reader: ->
- reader = new Reader
- reader.docs = @docs
- reader.read()
+ use_reader: -> @_docs = new Reader().read()
read_docs: ->
return @use_reader() if settings.docs.source isnt 'files'
@@ -39,13 +41,12 @@ class @Files
@find_files settings.docs.root, docs_type, @add_doc
- add_doc: => @docs.push
- name: path.basename @file, settings.docs.type
- steps: @doc.read @contents()
+ add_doc: => @_docs.add(
+ path.basename @file, settings.docs.type
+ @contents()
+ )
- add_suite: (name) -> @docs.push
- name: name
- is_suite: true
+ add_suite: (name) -> @_docs.add_suite path.basename name
contents: -> fs.readFileSync @file, 'utf8'
View
10 src/reports/teamcity.coffee
@@ -11,10 +11,10 @@ class @Report
suite: (it) -> @suites.report it
start_suite: (suite) ->
- @report "SuiteStarted name='#{@suite.name}'"
+ @report "SuiteStarted name='#{suite.name}'"
stop_suite: (suite) ->
- @report "SuiteFinished name='#{@suite.name}' duration='#{@suite.duration}'"
+ @report "SuiteFinished name='#{suite.name}' duration='#{suite.duration}'"
running: (@name) ->
@stats.start()
@@ -25,10 +25,10 @@ class @Report
@[@stats.stop @results]()
passed: -> @report "Finished name='#{@name}' duration='#{@stats.duration}'"
- failed: -> @report "Failed name='#{@name}' message='#{@message()}'"
- pending: -> @report "Ignored name='#{@name}' message'#{@message()}'"
+ failed: -> @report "Failed name='#{@name}' message=\"#{@message()}\""
+ pending: -> @report "Ignored name='#{@name}' message=\"#{@message()}\""
- message: -> _.escape @stats.messages().join '\n'
+ message: -> @stats.messages().join '\n'
stop: ->

0 comments on commit 3690a87

Please sign in to comment.