quarry 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ module Quarry
14
14
  # 4.should == 3 #=> Expectation Error
15
15
  #
16
16
  def should
17
- return Expectation.new(:delegate=>self, :backtrace=>caller)
17
+ return Expectation.new(self, :backtrace=>caller)
18
18
  end
19
19
 
20
20
  # Designate a negated expectation via a *functor*.
@@ -25,7 +25,7 @@ module Quarry
25
25
  # See also #expect!
26
26
  #
27
27
  def should!
28
- return Expectation.new(:delagte=>self, :negate=>true, :backtrace=>caller)
28
+ return Expectation.new(self, :negate=>true, :backtrace=>caller)
29
29
  end
30
30
 
31
31
  # See #should! method.
@@ -1,4 +1,10 @@
1
1
  require 'quarry/markup/step'
2
+ require 'quarry/markup/header'
3
+ require 'quarry/markup/comment'
4
+ require 'quarry/markup/macro'
5
+ require 'quarry/markup/before'
6
+ require 'quarry/markup/after'
7
+ require 'quarry/markup/table'
2
8
 
3
9
  module Quarry
4
10
 
@@ -41,18 +47,27 @@ module Quarry
41
47
  #text << line
42
48
  steps << Header.new(self, text, lineno)
43
49
  when /^\s+/
44
- last = steps.last
45
- case last
50
+ case last = steps.last
46
51
  when Step, Macro
47
52
  last.code << "\n\n#{text.rstrip}"
48
53
  when Comment
49
- if last.macro?
50
- steps << Macro.new(self, text, lineno, last.type)
54
+ if last.text =~ /\A([A-Z]{1,9})[:]/
55
+ #if macro = Macro.types.find{ |m| m.match?(last.text) }
56
+ type = Markup.const_get($1.capitalize)
57
+ step = type.new(self, text, lineno, :comment=>last.text, :before=>@before, :after=>@after)
58
+ case step
59
+ when Before
60
+ @before = step
61
+ when After
62
+ @after = step
63
+ end
64
+ steps << step
51
65
  else
52
- steps << Step.new(self, text, lineno)
66
+ steps << Step.new(self, text, lineno, :before=>@before, :after=>@after)
53
67
  end
54
68
  else
55
- steps << Step.new(self, text, lineno)
69
+ raise "never here"
70
+ steps << Step.new(self, text, lineno, :before=>@before, :after=>@after)
56
71
  end
57
72
  else
58
73
  steps << Comment.new(self, text, lineno)
@@ -64,6 +79,17 @@ module Quarry
64
79
  File.basename(file)
65
80
  end
66
81
 
82
+ #
83
+ def to_script
84
+ script = []
85
+ Dir.chdir(File.dirname(file)) do
86
+ steps.each do |step|
87
+ script << step.to_script
88
+ end
89
+ end
90
+ script.join("\n\n")
91
+ end
92
+
67
93
  end #class Markup
68
94
 
69
95
  end#module Quarry
@@ -0,0 +1,28 @@
1
+ require 'quarry/markup/macro'
2
+
3
+ module Quarry
4
+
5
+ class Markup #:nodoc:
6
+
7
+ class After < Macro
8
+ #def self.match?(comment)
9
+ # comment =~ /^AFTER/i
10
+ #end
11
+
12
+ # Run after macro.
13
+ def run(runner, spec, context, output)
14
+ #runner.after = code
15
+ output.report_macro(self)
16
+ end
17
+
18
+ #
19
+ def to_script
20
+ code.gsub(/^/, '# ')
21
+ end
22
+
23
+ end
24
+
25
+ end #class Markup
26
+
27
+ end #module Quarry
28
+
@@ -0,0 +1,28 @@
1
+ require 'quarry/markup/macro'
2
+
3
+ module Quarry
4
+
5
+ class Markup #:nodoc:
6
+
7
+ class Before < Macro
8
+ #def self.match?(comment)
9
+ # comment =~ /^BEFORE/i
10
+ #end
11
+
12
+ # Run before macro.
13
+ def run(runner, spec, context, output)
14
+ #runner.before = code
15
+ output.report_macro(self)
16
+ end
17
+
18
+ #
19
+ def to_script
20
+ code.gsub(/^/, '# ')
21
+ end
22
+
23
+ end
24
+
25
+ end #class Markup
26
+
27
+ end #module Quarry
28
+
@@ -0,0 +1,56 @@
1
+ module Quarry
2
+
3
+ class Markup #:nodoc:
4
+
5
+ # = Comment
6
+ #
7
+ class Comment
8
+
9
+ attr :spec
10
+ attr :text
11
+ attr :lineno
12
+
13
+ def initialize(spec, text, lineno)
14
+ @spec = spec
15
+ @text = text.strip
16
+ @lineno = lineno
17
+ end
18
+
19
+ alias_method :parent, :spec
20
+ alias_method :description, :text
21
+
22
+ # Matches the beginning of text to
23
+ # determine if this defines a macro section.
24
+ def type
25
+ /\A(\w{1,9})[:]\ /i =~ text
26
+ $1.downcase.to_sym if $1
27
+ end
28
+ alias_method :macro?, :type
29
+
30
+ # "run" comment.
31
+ def run(runner, spec, context, output)
32
+ output.report_comment(self)
33
+ end
34
+
35
+ #
36
+ def to_s
37
+ text.to_s
38
+ end
39
+
40
+ # As could appear in stand-alone script.
41
+ def to_script
42
+ text.to_s.gsub(/^/m, '# ')
43
+ end
44
+
45
+ end #class Comment
46
+
47
+ end #class Markup
48
+
49
+ end #module Quarry
50
+
51
+
52
+ # TABLE: "mytable.yaml" This is what and so on.
53
+ # This is so it will be wahtever fi so.
54
+ #
55
+ # fdsffsdf
56
+
@@ -0,0 +1,42 @@
1
+ module Quarry
2
+
3
+ class Markup #:nodoc:
4
+
5
+ # = Header
6
+ #
7
+ class Header
8
+
9
+ attr :spec
10
+ attr :text
11
+ attr :lineno
12
+
13
+ def initialize(spec, text, lineno)
14
+ @parent = spec
15
+ @text = text.strip
16
+ @lineno = lineno
17
+ end
18
+
19
+ alias_method :parent, :spec
20
+ alias_method :description, :text
21
+
22
+ # "run" comment.
23
+ def run(runner, spec, context, output)
24
+ output.report_header(self)
25
+ end
26
+
27
+ #
28
+ def to_s
29
+ text.to_s
30
+ end
31
+
32
+ # As would appear in stand-alone script.
33
+ def to_script
34
+ text.to_s.gsub(/^/m, '# ')
35
+ end
36
+
37
+ end #class Header
38
+
39
+ end #class Markup
40
+
41
+ end #module Quarry
42
+
@@ -0,0 +1,53 @@
1
+ module Quarry
2
+
3
+ class Markup #:nodoc:
4
+
5
+ # = Macro
6
+ #
7
+ class Macro #< Step
8
+
9
+ #def self.inherited(subclass)
10
+ # types << subclass
11
+ #end
12
+
13
+ #def self.types
14
+ # @types ||= []
15
+ #end
16
+
17
+ attr :spec
18
+ attr :code
19
+ attr :lineno
20
+
21
+ def initialize(spec, code, lineno, ioc={})
22
+ @spec = spec
23
+ @code = code.rstrip
24
+ @lineno = lineno
25
+ end
26
+
27
+ alias_method :parent, :spec
28
+
29
+ # Run macro.
30
+ def run(runner, spec, context, output)
31
+ context.instance_eval(code, spec.file, lineno)
32
+ output.report_macro(self)
33
+ end
34
+
35
+ #
36
+ def tab
37
+ @tab ||= to_s.index(/\S/)
38
+ end
39
+
40
+ #
41
+ def to_s ; code ; end
42
+
43
+ # As could appear in stand-alone script.
44
+ def to_script
45
+ code.to_s
46
+ end
47
+
48
+ end
49
+
50
+ end #class Markup
51
+
52
+ end #module Quarry
53
+
@@ -5,72 +5,68 @@ module Quarry
5
5
  # = Step
6
6
  #
7
7
  class Step
8
- attr :parent
8
+
9
+ attr :spec
9
10
  attr :code
10
11
  attr :lineno
11
12
 
12
- def initialize(parent, code, lineno)
13
- @parent = parent
13
+ attr :before
14
+ attr :after
15
+
16
+ def initialize(spec, code, lineno, ioc={})
17
+ @spec = spec
14
18
  @code = code.rstrip
15
19
  @lineno = lineno
20
+
21
+ @before = ioc[:before]
22
+ @after = ioc[:after]
16
23
  end
17
24
 
18
- alias_method :spec, :parent
25
+ alias_method :parent, :spec
19
26
 
20
27
  #def description
21
28
  # alias_method :description, :text
22
29
  #end
23
- end
24
30
 
25
- # = Macro
26
- #
27
- class Macro < Step
28
- attr :type
29
- def initialize(parent, code, lineno, type)
30
- super(parent, code, lineno)
31
- @type = type
31
+ # Run specification step.
32
+ #
33
+ # TODO: Would spec.before + spec.code be better?
34
+ #
35
+ def run(runner, spec, context, output)
36
+ output.report_step(self)
37
+ #context.instance_eval(runner.before, spec.file) if runner.before
38
+ context.instance_eval(before.code, spec.file) if before
39
+ begin
40
+ context.instance_eval(code, spec.file, lineno)
41
+ output.report_pass(self)
42
+ rescue Assertion => error
43
+ output.report_fail(self, error)
44
+ rescue Exception => error
45
+ output.report_error(self, error)
46
+ ensure
47
+ context.instance_eval(after.code, spec.file) if after
48
+ #context.instance_eval(runner.after, spec.file) if runner.after
49
+ end
32
50
  end
33
- end
34
-
35
- # = Header
36
- #
37
- class Header
38
- attr :parent
39
- attr :text
40
- attr :lineno
41
51
 
42
- def initialize(parent, text, lineno)
43
- @parent = parent
44
- @text = text.strip
45
- @lineno = lineno
52
+ #
53
+ def tab
54
+ @tab ||= to_s.index(/\S/)
46
55
  end
47
56
 
48
- alias_method :spec, :parent
49
- alias_method :description, :text
50
- end
51
-
52
- # = Comment
53
- #
54
- class Comment
55
- attr :parent
56
- attr :text
57
- attr :lineno
58
-
59
- def initialize(parent, text, lineno)
60
- @parent = parent
61
- @text = text.strip
62
- @lineno = lineno
57
+ #
58
+ def to_s
59
+ code
63
60
  end
64
61
 
65
- alias_method :spec, :parent
66
- alias_method :description, :text
67
-
68
- #
69
- def type
70
- /^(\w{1,9})[:]/i =~ text
71
- $1.downcase.to_sym if $1
62
+ # As could appear in stand-alone script.
63
+ def to_script
64
+ script = []
65
+ script << before.code if before
66
+ script << code
67
+ script << before.code if after
68
+ script .join("\n")
72
69
  end
73
- alias_method :macro?, :type
74
70
  end
75
71
 
76
72
  end #class Markup
@@ -0,0 +1,89 @@
1
+ require 'yaml'
2
+ require 'quarry/markup/step'
3
+
4
+ module Quarry
5
+
6
+ class Markup #:nodoc:
7
+
8
+ # = Table
9
+ #
10
+ class Table < Step
11
+ attr :file
12
+ attr :data
13
+ attr :vars
14
+
15
+ def initialize(spec, code, lineno, ioc={})
16
+ super(spec, code, lineno, ioc)
17
+
18
+ comment = ioc[:comment]
19
+
20
+ if md = /\(\*?\)/.match(comment)
21
+ @fname = md[1]
22
+ else
23
+ @fname = 'default.yaml' # TODO: more intelligent default?
24
+ end
25
+
26
+ @file = File.join('tables', @fname)
27
+ end
28
+
29
+ def load_table
30
+ table = YAML.load(File.new(file)) # yaml or csv ?
31
+ vars, *data = *table
32
+ return vars, data
33
+ end
34
+
35
+ # Run a specification tabular step.
36
+ #
37
+ # TODO: Table reporting needs to be improved.
38
+ # TODO: Currently on simple object types can be used b/c of set's use of #inspect.
39
+ #
40
+ def run(runner, spec, context, output)
41
+ vars, rows = *load_table
42
+
43
+ #context.instance_eval(runner.before, spec.file) if runner.before
44
+ context.instance_eval(before.code, spec.file) if before
45
+
46
+ begin
47
+ output.report_macro(self); puts #(little bit of a hack here)
48
+ rows.each do |row|
49
+ set = vars.zip(row).map{ |a| "#{a[0]}=#{a[1].inspect}" }.join('; ')
50
+ set = (' ' * tab) + set
51
+ code = "#{set}\n#{code()}"
52
+ step = Step.new(spec, set, lineno) # fuax step
53
+ begin
54
+ context.instance_eval(code, spec.file, lineno)
55
+ #output.report_literal(set)
56
+ output.report_pass(step) #(self)
57
+ rescue Assertion => error
58
+ output.report_fail(step, error) #(self, error)
59
+ rescue Exception => error
60
+ output.report_error(step, error) #(self, error)
61
+ end
62
+ end
63
+ ensure
64
+ #context.instance_eval(runner.after, spec.file) if runner.after
65
+ context.instance_eval(after.code, spec.file) if after
66
+ end
67
+ end
68
+
69
+ #
70
+ def to_script
71
+ script = []
72
+ vars, rows = *load_table
73
+ script << before.code if before
74
+ rows.each do |row|
75
+ set = vars.zip(row).map{ |a| "#{a[0]}=#{a[1].inspect}" }.join('; ')
76
+ set = (' ' * tab) + set
77
+ code = "#{set}\n#{code()}"
78
+ script << code
79
+ end
80
+ script << after.code if after
81
+ script.join("\n")
82
+ end
83
+
84
+ end #class Table
85
+
86
+ end #class Markup
87
+
88
+ end #module Quarry
89
+