concordion 0.9.9.2 → 0.9.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/README +0 -0
  2. data/Rakefile.rb +25 -28
  3. data/documentation/index.html +88 -0
  4. data/documentation/p/rcor/wiki/Tutorial/index.html +75 -0
  5. data/lib/concordion/binder.rb +26 -0
  6. data/lib/concordion/constants.rb +15 -0
  7. data/lib/{concordion_css.rb → concordion/css.rb} +9 -7
  8. data/lib/concordion/css_decorator.rb +59 -0
  9. data/lib/concordion/environment.rb +28 -0
  10. data/lib/concordion/error_condition.rb +27 -0
  11. data/lib/concordion/instrumenter.rb +31 -0
  12. data/lib/concordion/invoker.rb +148 -0
  13. data/lib/concordion/loader_helper.rb +17 -0
  14. data/lib/concordion/lookahead_handler.rb +16 -0
  15. data/lib/concordion/parse_result.rb +74 -0
  16. data/lib/concordion/parser.rb +43 -0
  17. data/lib/concordion/processor.rb +24 -0
  18. data/lib/concordion/reader.rb +11 -0
  19. data/lib/concordion/state.rb +77 -0
  20. data/lib/concordion/string_utility.rb +104 -0
  21. data/lib/concordion/string_writer.rb +13 -0
  22. data/lib/concordion/test_methods.rb +130 -0
  23. data/lib/concordion/utility.rb +72 -0
  24. data/lib/concordion/verifier.rb +52 -0
  25. data/lib/concordion/writer.rb +52 -0
  26. data/lib/concordion_test_case.rb +4 -16
  27. data/lib/goldmaster_test_case.rb +4 -4
  28. data/ruby-concordion.tmproj +249 -0
  29. data/test/concordion/css_decorator_test.rb +28 -0
  30. data/test/concordion/environment_test.rb +46 -0
  31. data/test/concordion/invoker_test.rb +20 -0
  32. data/test/concordion/parse_result_test.rb +51 -0
  33. data/test/concordion/reader_test.rb +12 -0
  34. data/test/concordion/state_test.rb +41 -0
  35. data/test/concordion/string_writer_test.rb +10 -0
  36. data/test/concordion/utility_test.rb +142 -0
  37. data/test/concordion/verifier_test.rb +38 -0
  38. data/test/concordion/writer_test.rb +29 -0
  39. data/{tests → test}/concordion.css +0 -0
  40. data/{tests/concordion → test}/goldmaster_test_case_test.rb +2 -8
  41. data/{tests → test/spec}/basic_assert.html +0 -0
  42. data/{tests → test/spec}/basic_assert_test.rb +2 -2
  43. data/{tests → test/spec}/basic_set.html +0 -0
  44. data/{tests → test/spec}/basic_set_test.rb +0 -1
  45. data/{tests → test/spec}/basic_text.html +0 -0
  46. data/{tests → test/spec}/basic_text_test.rb +0 -1
  47. data/{tests → test/spec}/failing.html +0 -0
  48. data/{tests → test/spec}/failing_test.rb +0 -1
  49. data/{tests → test/spec}/goldmasters/failing_with_subclass.html +0 -0
  50. data/{tests → test/spec}/goldmasters/failing_with_subclass_goldmaster.html +0 -0
  51. data/{tests → test/spec}/goldmasters/failing_with_subclass_test.rb +2 -2
  52. data/{tests → test/spec}/goldmasters/goldmaster_assert_true_failing.html +0 -0
  53. data/{tests → test/spec}/goldmasters/goldmaster_assert_true_failing_goldmaster.html +0 -0
  54. data/{tests → test/spec}/goldmasters/goldmaster_assert_true_failing_test.rb +0 -0
  55. data/{tests → test/spec}/goldmasters/goldmaster_failing.html +0 -0
  56. data/{tests → test/spec}/goldmasters/goldmaster_failing_goldmaster.html +0 -0
  57. data/{tests → test/spec}/goldmasters/goldmaster_failing_test.rb +0 -2
  58. data/{tests → test/spec}/goldmasters/goldmaster_malformed.html +0 -0
  59. data/{tests → test/spec}/goldmasters/goldmaster_malformed_goldmaster.html +0 -0
  60. data/{tests → test/spec}/goldmasters/goldmaster_malformed_test.rb +0 -0
  61. data/{tests → test/spec}/goldmasters/goldmaster_passing.html +0 -0
  62. data/{tests → test/spec}/goldmasters/goldmaster_passing_goldmaster.html +0 -0
  63. data/{tests → test/spec}/goldmasters/goldmaster_passing_test.rb +0 -0
  64. data/{tests → test/spec}/goldmasters/goldmaster_table.html +0 -0
  65. data/{tests → test/spec}/goldmasters/goldmaster_table_bug.html +0 -0
  66. data/{tests → test/spec}/goldmasters/goldmaster_table_bug_goldmaster.html +0 -0
  67. data/{tests → test/spec}/goldmasters/goldmaster_table_bug_test.rb +0 -0
  68. data/{tests → test/spec}/goldmasters/goldmaster_table_goldmaster.html +0 -0
  69. data/{tests → test/spec}/goldmasters/goldmaster_table_test.rb +1 -0
  70. data/{tests → test/spec}/image.html +0 -0
  71. data/{tests → test/spec}/image.jpg +0 -0
  72. data/{tests → test/spec}/image_test.rb +2 -2
  73. data/{tests → test/spec}/link_style_css.html +0 -0
  74. data/{tests → test/spec}/link_style_css_test.rb +1 -6
  75. data/{tests → test/spec}/lookahead_assert_true.html +0 -0
  76. data/{tests → test/spec}/lookahead_assert_true_test.rb +0 -0
  77. data/{tests → test/spec}/mixed.html +0 -0
  78. data/test/spec/mixed_test.rb +13 -0
  79. data/{tests → test/spec}/nested_element_lookahead.html +0 -0
  80. data/{tests → test/spec}/nested_element_lookahead_test.rb +0 -0
  81. data/{tests → test/spec}/numbers.html +0 -0
  82. data/{tests → test/spec}/numbers_test.rb +0 -0
  83. data/{tests → test/spec}/processes_elements_in_sorted_order.html +0 -0
  84. data/{tests → test/spec}/processes_elements_in_sorted_order_test.rb +0 -0
  85. data/{tests → test/spec}/return_result.html +0 -0
  86. data/{tests → test/spec}/return_result_test.rb +0 -0
  87. data/test/spec/structure/maps_to_module.html +11 -0
  88. data/test/spec/structure/maps_to_module_test.rb +13 -0
  89. data/{tests → test/spec}/tables/single_row_table.html +0 -0
  90. data/{tests → test/spec}/tables/single_row_table_test.rb +0 -0
  91. data/{tests → test/spec}/tables/table.html +0 -0
  92. data/{tests → test/spec}/tables/table_test.rb +1 -0
  93. data/{tests → test/spec}/tables/test_helper.rb +3 -7
  94. data/{tests → test/spec}/tables/verify_rows.html +0 -0
  95. data/{tests → test/spec}/tables/verify_rows_scsr.html +0 -0
  96. data/{tests → test/spec}/tables/verify_rows_scsr_test.rb +2 -1
  97. data/{tests → test/spec}/tables/verify_rows_simple.html +0 -0
  98. data/{tests → test/spec}/tables/verify_rows_simple_test.rb +0 -0
  99. data/{tests → test/spec}/tables/verify_rows_test.rb +1 -0
  100. data/{tests → test/spec}/user-reported/apostrophe.html +0 -0
  101. data/{tests → test/spec}/user-reported/apostrophe_test.rb +0 -1
  102. data/{tests → test/spec}/user-reported/ariel_example.html +0 -0
  103. data/{tests → test/spec}/user-reported/ariel_example_test.rb +0 -0
  104. data/{tests → test/spec}/user-reported/attr_assert.html +0 -0
  105. data/{tests → test/spec}/user-reported/attr_assert_test.rb +0 -1
  106. data/{tests → test/spec}/user-reported/basic_assert_true.html +0 -0
  107. data/{tests → test/spec}/user-reported/basic_assert_true_test.rb +1 -2
  108. data/{tests → test/spec}/user-reported/rubyish.html +0 -0
  109. data/{tests → test/spec}/user-reported/rubyish_test.rb +0 -1
  110. data/test/test_helper.rb +11 -0
  111. metadata +131 -114
  112. data/lib/concordion_binder.rb +0 -24
  113. data/lib/concordion_constants.rb +0 -13
  114. data/lib/concordion_css_decorator.rb +0 -58
  115. data/lib/concordion_environment.rb +0 -27
  116. data/lib/concordion_error_condition.rb +0 -26
  117. data/lib/concordion_instrumenter.rb +0 -30
  118. data/lib/concordion_invoker.rb +0 -137
  119. data/lib/concordion_lookahead_handler.rb +0 -17
  120. data/lib/concordion_parse_result.rb +0 -72
  121. data/lib/concordion_parser.rb +0 -47
  122. data/lib/concordion_processor.rb +0 -25
  123. data/lib/concordion_reader.rb +0 -10
  124. data/lib/concordion_state.rb +0 -78
  125. data/lib/concordion_string_utility.rb +0 -97
  126. data/lib/concordion_string_writer.rb +0 -13
  127. data/lib/concordion_test_methods.rb +0 -132
  128. data/lib/concordion_utility.rb +0 -70
  129. data/lib/concordion_verifier.rb +0 -50
  130. data/lib/concordion_writer.rb +0 -43
  131. data/lib/loader_helper.rb +0 -16
  132. data/tests/concordion/concordion_css_decorator_test.rb +0 -28
  133. data/tests/concordion/concordion_environment_test.rb +0 -44
  134. data/tests/concordion/concordion_parse_result_test.rb +0 -51
  135. data/tests/concordion/concordion_reader_test.rb +0 -15
  136. data/tests/concordion/concordion_state_test.rb +0 -38
  137. data/tests/concordion/concordion_string_writer_test.rb +0 -13
  138. data/tests/concordion/concordion_utility_test.rb +0 -135
  139. data/tests/concordion/concordion_verifier_test.rb +0 -38
  140. data/tests/concordion/concordion_writer_test.rb +0 -26
  141. data/tests/mixed_test.rb +0 -19
@@ -0,0 +1,74 @@
1
+ require 'concordion/utility'
2
+
3
+ module Concordion
4
+ class ParseResult
5
+ include Concordion::Utility
6
+ attr_accessor :concordion_command, :system_under_test, :content, :tag
7
+ def initialize(cmd, sut, content, tag)
8
+ @concordion_command = cmd
9
+ @system_under_test = sut
10
+ @content = content
11
+ @tag = tag
12
+ end
13
+ def to_s
14
+ "Concordion command[#{@concordion_command}], System under test method[#{@system_under_test}], Tag Content[#{@content}] Image Location[#{image_location}]"
15
+ end
16
+
17
+ def is_assert_image_command?
18
+ "assert_image" == @concordion_command
19
+ end
20
+
21
+ def is_set_command?
22
+ "set" == @concordion_command
23
+ end
24
+ def is_verify_command?
25
+ "verifyrows" == @concordion_command
26
+ end
27
+ def is_execute_command?
28
+ "execute" == @concordion_command
29
+ end
30
+ def is_assert_true_command?
31
+ "asserttrue" == @concordion_command
32
+ end
33
+
34
+ def num_results_expected
35
+ @tag.search("tr").size - 1
36
+ end
37
+
38
+ def image_location
39
+ return nil if @tag.nil?
40
+ @tag.get_attribute('src')
41
+ end
42
+
43
+ def assignment
44
+ concordion_assignment(@system_under_test)
45
+ end
46
+
47
+ def needs_dereference?
48
+ @system_under_test =~ /^#/ && @system_under_test.index("=").nil?
49
+ end
50
+
51
+ def verify_error(actual, expected)
52
+ if actual > expected
53
+ diff = actual - expected
54
+ @tag.inner_html += "<tr><td>[#{diff} Surplus Row(s) Returned By Fixture]</td></tr>"
55
+ end
56
+ end
57
+
58
+ def assertion_error(actual)
59
+ if is_assert_true_command?
60
+ @tag.inner_html += ": expected true but received #{actual}"
61
+ else
62
+ @tag.inner_html += " expected but received #{actual}"
63
+ end
64
+ end
65
+
66
+ def attribute_error(actual, expected)
67
+ if is_verify_command?
68
+ verify_error(actual, expected)
69
+ else
70
+ assertion_error(actual)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,43 @@
1
+ require 'concordion/instrumenter'
2
+ require 'rubygems'
3
+ require 'hpricot'
4
+
5
+ module Concordion
6
+ class Parser
7
+ @@ALL_ATTRIBUTED_ELEMENTS = "/html/body//*[@*]"
8
+
9
+ include Concordion::Utility
10
+
11
+ attr_accessor :root, :body, :html
12
+
13
+ def initialize(reader, concordion)
14
+ @reader = reader
15
+ @concordion = concordion
16
+ @verifier = concordion.verifier
17
+ @instrumenter = Concordion::Instrumenter.new
18
+ end
19
+
20
+ def parse(filename)
21
+ @root = Hpricot.parse(@reader.read(filename))
22
+ @body = @root.at("body")
23
+ @html = @root.at("html")
24
+ end
25
+ def each_concordion_element(&block)
26
+ @root.search(@@ALL_ATTRIBUTED_ELEMENTS).each {|elem|
27
+ yield elem
28
+ }
29
+ end
30
+
31
+ def each_eligible_concordion_element(&block)
32
+ each_concordion_element do |elem|
33
+ if concordion_cmd_attr_exists?(elem)
34
+ attr = concordion_cmd_attr_for(elem)
35
+ @verifier.update_row(elem)
36
+ if !@instrumenter.instrument_from_headers(elem, attr, @root)
37
+ yield elem
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ require 'concordion/utility'
2
+
3
+ module Concordion
4
+ class Processor
5
+ include Concordion::Utility
6
+
7
+ def initialize(concordion, decorator)
8
+ @concordion = concordion
9
+ @decorator = decorator
10
+ end
11
+
12
+ def process(tag, test_context)
13
+ attr = concordion_cmd_attr_for(tag)
14
+ instrumented_value = tag.get_attribute(attr)
15
+ cpr = create_parse_result(tag, attr, instrumented_value)
16
+ rv = @concordion.evaluate(cpr, test_context, self)
17
+ @decorator.decorate_tag(rv, tag, cpr)
18
+ end
19
+
20
+ def create_parse_result(tag, attr, value)
21
+ Concordion::ParseResult.new(instrumentation(attr), value, tag.inner_text, tag)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'concordion/loader_helper'
2
+
3
+ module Concordion
4
+ class Reader
5
+ include Concordion::LoaderHelper
6
+ def read(filename)
7
+ IO.read(path_for(filename))
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,77 @@
1
+ require 'concordion/utility'
2
+ require 'concordion/lookahead_handler'
3
+ require 'concordion/verifier'
4
+ require 'concordion/invoker'
5
+ require 'concordion/binder'
6
+
7
+ module Concordion
8
+ # Concordion State manages memory for Concordion specs as they are being parsed (e.g. when #var is declared in a spec, this class holds the memory reference).
9
+ class State
10
+ include Concordion::Utility
11
+
12
+ @@TEXT_VAR = "#TEXT"
13
+ def self.TEXT_VAR
14
+ @@TEXT_VAR
15
+ end
16
+ attr_reader :verification_variable, :verifier
17
+
18
+ def initialize
19
+ @memory = {}
20
+ @lookahead_handler = Concordion::LookaheadHandler.new
21
+ @verifier = Concordion::Verifier.new(self)
22
+ @invoker = Concordion::Invoker.new(self)
23
+ @binder = Concordion::Binder.new(self)
24
+ set_variable(@@TEXT_VAR, @@TEXT_VAR)
25
+ end
26
+
27
+ def set_variable(variable, value)
28
+ @memory[variable] = value
29
+ end
30
+
31
+ def get_variable(variable)
32
+ @memory[variable]
33
+ end
34
+
35
+
36
+ # Deferences concordion method calls.
37
+ # For example if memory held:
38
+ # * #foo => 12
39
+ # * #bar => 4
40
+ # Then the following mappings hold:
41
+ # * #foo => 12
42
+ # * #foo.to_f => 12.0
43
+ # * method(#foo, #bar) => method(12, 4)
44
+
45
+ def dereference(conc_call)
46
+ var_name = concordion_variable_name(conc_call)
47
+ var = get_variable(var_name)
48
+
49
+ if !has_property_reference?(conc_call)
50
+ return var
51
+ end
52
+
53
+ var.send(concordion_property_reference(conc_call))
54
+ end
55
+
56
+ # Evaluate an expression
57
+ # 1. Lookahead in the tag to see if needed variables are bound later.
58
+ # 2. Bind a value to the variable from the spec, if needed. Returns early if bound successfully.
59
+ # 3. Update the current value of the iterator for verification commands, if needed.
60
+ # 4. Invoke the system under test
61
+ # 5. Bind a value to the variable on the left hand side of an equation, if needed.
62
+ # 6. Hand the system under test return value to the concordion invoker, which makes the assertion.
63
+ def evaluate(cpr, test_context, processor)
64
+ @lookahead_handler.handle_lookahead(cpr, test_context, processor)
65
+
66
+ return { :result => true } if @binder.bind_if_set_command(cpr)
67
+
68
+ @verifier.update_if_verify_command(cpr)
69
+
70
+ sut_rv = @invoker.invoke_sut(cpr, test_context)
71
+ @binder.handle_assignment(cpr, sut_rv)
72
+ conc_rv = @invoker.invoke_concordion(cpr, sut_rv)
73
+
74
+ conc_rv
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,104 @@
1
+ module Concordion
2
+ module SnakeCaseUtility
3
+
4
+ def snake_case(str)
5
+ file_parts = str.split "::"
6
+
7
+ s = file_parts.pop
8
+ s = s.gsub( /([A-Z])/, '_\1')
9
+
10
+ if s.index("_") == 0
11
+ s = s.slice(1, s.length)
12
+ end
13
+
14
+ file_parts << s
15
+ file_parts.join('/').downcase
16
+ end
17
+
18
+ def snake_cased_test_name(str)
19
+ s = snake_case(str)
20
+ s = s.gsub(/_test$/, '')
21
+
22
+ "#{s}.html"
23
+ end
24
+
25
+ def snake_cased_goldmaster_name(str)
26
+ snake_cased_test_name(str).gsub(".html", "_goldmaster.html")
27
+ end
28
+
29
+ end
30
+
31
+ module PluralToSingularUtility
32
+
33
+ def singular(str)
34
+ str.sub(/s$/, "")
35
+ end
36
+ end
37
+
38
+ module StringUtility
39
+ include SnakeCaseUtility
40
+ include PluralToSingularUtility
41
+
42
+ def has_arguments?(name)
43
+ !(ends_in_empty_parens?(name) || is_direct_method_call?(name))
44
+ end
45
+
46
+ def is_direct_method_call?(name)
47
+ name =~ /^[\w]+$/
48
+ end
49
+
50
+ def ends_in_empty_parens?(name)
51
+ name =~ /\(\)$/
52
+ end
53
+
54
+ def concordion_assignment(name)
55
+ name.split("=")[0].strip
56
+ end
57
+
58
+ def has_assignment?(name)
59
+ name =~ /=/
60
+ end
61
+
62
+ def attr_writer_method?(name)
63
+ name =~ /=$/
64
+ end
65
+
66
+ def concordion_method_name(name)
67
+ if name =~ /\(/
68
+ base = name.split("(")[0].strip
69
+ else
70
+
71
+
72
+ base = name.strip
73
+ if base =~ /\s/
74
+
75
+ if base =~ /=/ && base =~ /^#/
76
+ base = base.split("=")[1].strip
77
+ end
78
+ elements = base.split(/\s/)
79
+ base = elements[0]
80
+ end
81
+ end
82
+
83
+ if !has_assignment?(base)
84
+ return base
85
+ end
86
+
87
+ if attr_writer_method?(base)
88
+ return base if base.count("=") == 1
89
+ return assignment(base) + "="
90
+ end
91
+
92
+ assignment(base)
93
+ end
94
+
95
+ def assignment(base)
96
+ base.split("=")[1].strip
97
+ end
98
+
99
+ def escape_single_quotes(s)
100
+ s.gsub(/[']/, '\\\\\\\\\'')
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,13 @@
1
+ module Concordion
2
+ class StringWriter
3
+ attr_accessor :data
4
+ def calculate_filename_and_overwrite(data, filename)
5
+ @data = data.to_s
6
+ filename
7
+ end
8
+
9
+ def output_file_exists?(filename)
10
+ true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,130 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+ require 'concordion/writer'
4
+ require 'concordion/environment'
5
+ require 'concordion/css_decorator'
6
+ require 'concordion/state'
7
+ require 'concordion/reader'
8
+ require 'concordion/parser'
9
+ require 'concordion/processor'
10
+ require 'concordion/parse_result'
11
+
12
+ module Concordion
13
+
14
+ module ConfigMethods
15
+
16
+ def default_config
17
+ concordion = Concordion::State.new
18
+ parser = Concordion::Parser.new(Concordion::Reader.new, concordion)
19
+ decorator = Concordion::CSSDecorator.new
20
+ processor = Concordion::Processor.new(concordion, decorator)
21
+ {
22
+ :parser => parser,
23
+ :writer => Concordion::Writer.new(Concordion::Environment.output_dir),
24
+ :concordion => concordion,
25
+ :decorator => decorator,
26
+ :processor => processor,
27
+ :write_goldmaster => false,
28
+ :css_type => Concordion::Environment.css_type
29
+ }
30
+ end
31
+
32
+ def bind_test_method_to(subclass, config)
33
+ subclass.class_eval do
34
+ define_method :test_spec do
35
+ filename = snake_cased_test_name(subclass.to_s)
36
+ parse_spec(filename,config)
37
+ failures = run_spec(filename, config)
38
+ report_spec(filename,config, failures)
39
+ end
40
+ end
41
+ subclass
42
+ end
43
+
44
+ end
45
+
46
+ module InternalTestMethods
47
+ @@EXPECTED_FAILURE_COUNT = 0
48
+ include Concordion::Utility
49
+
50
+ def parse_spec(filename,config)
51
+ config[:parser].parse(filename)
52
+ assert_concordion_document(config)
53
+ if self.class.method_defined?(:css_type)
54
+ config[:decorator].add_concordion_css_link(config[:parser].root, config[:parser].html, css_type)
55
+ else
56
+ config[:decorator].add_concordion_css_link(config[:parser].root, config[:parser].html, config[:css_type])
57
+ end
58
+
59
+ end
60
+
61
+ def run_spec(filename, config)
62
+ failures = []
63
+ config[:parser].each_eligible_concordion_element do |elem|
64
+ failure = config[:processor].process(elem, self)
65
+ failures << failure unless failure.nil?
66
+ end
67
+ failures
68
+ end
69
+
70
+ def report_spec(filename, config, failures)
71
+ config[:decorator].add_css_file_to_output_dir(config[:writer], config[:css_type])
72
+
73
+ writer = config[:writer]
74
+ if self.class.method_defined?(:rcor_writer)
75
+ writer = rcor_writer()
76
+ end
77
+
78
+ outfilename = writer.calculate_filename_and_overwrite(config[:parser].root, filename)
79
+ assert_no_failures(outfilename, config, failures)
80
+ end
81
+
82
+ def assert_no_failures(outfilename, config, failures)
83
+ expected = @@EXPECTED_FAILURE_COUNT
84
+
85
+ if self.class.method_defined?(:expected_failure_count)
86
+ expected = expected_failure_count()
87
+ end
88
+
89
+ message = build_message "#{show_failures(failures)}\nWrote output to #{outfilename}.",
90
+ 'Actual failure count <?> did not match expected <?>.',
91
+ failures.size, expected
92
+ assert_block message do
93
+ failures.size == expected
94
+ end
95
+ end
96
+
97
+ def show_failures(failures)
98
+ rv = ""
99
+ failures.each_with_index do |failure, index|
100
+ rv += "[Error:#{index + 1}] #{failure}\n"
101
+ end
102
+ rv
103
+ end
104
+
105
+ def assert_concordion_document(config)
106
+ assert_equal "http://www.concordion.org/2007/concordion", config[:parser].html.get_attribute("xmlns:concordion")
107
+ end
108
+
109
+ end
110
+
111
+
112
+ module TestMethods
113
+ include InternalTestMethods
114
+ extend ConfigMethods
115
+
116
+ class << self
117
+ alias_method :original_included, :included
118
+ end
119
+
120
+ def self.included(cmod)
121
+ original_included(cmod)
122
+ conf = default_config
123
+ cm = class << cmod
124
+ include ConfigMethods
125
+ end
126
+
127
+ bind_test_method_to(cmod, conf)
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,72 @@
1
+
2
+ require 'concordion/constants'
3
+ require 'concordion/string_utility'
4
+
5
+ module Concordion
6
+ module Utility
7
+ include Concordion::Constants
8
+ include Concordion::StringUtility
9
+
10
+ def instrumentation(attr)
11
+ attr.split(":")[1]
12
+ end
13
+
14
+ def concordion_arguments(name)
15
+ return [] unless has_arguments?(name)
16
+ arg_string = nil
17
+ if name =~ /\(/
18
+ name_no_end_paren = name.gsub(")", '')
19
+ arg_string = name_no_end_paren.split("(")[1]
20
+ else
21
+
22
+ base = name.strip
23
+ if base =~ /=/
24
+ arg_string = nil
25
+ base = base.split("=")[1].strip
26
+ end
27
+ tokens = base.split(" ").compact
28
+ arg_string = tokens.slice(1, tokens.size - 1).join(" ")
29
+ end
30
+
31
+ arg_string.split(",").collect { |arg| arg.strip }
32
+ end
33
+
34
+ def concordion_variable_name(conc_call)
35
+ if has_property_reference?(conc_call)
36
+ return conc_call.split(".")[0].strip
37
+ end
38
+
39
+ conc_call.strip
40
+ end
41
+
42
+ def has_property_reference?(conc_call)
43
+ conc_call =~ /\./
44
+ end
45
+
46
+ def concordion_property_reference(conc_call)
47
+ if !has_property_reference?(conc_call)
48
+ return conc_call
49
+ end
50
+ idx = conc_call.index(".")
51
+ conc_call.slice(idx + 1, conc_call.length - idx).strip
52
+ end
53
+
54
+
55
+
56
+ def concordion_cmd_attr_exists?(elem)
57
+ !concordion_cmd_attr_for(elem).nil?
58
+ end
59
+
60
+ def concordion_cmd_attr_for(elem)
61
+ concordion_command_attributes.each {|attr|
62
+ instrumented_value = elem.get_attribute(attr)
63
+ if !instrumented_value.nil?
64
+ return attr
65
+ end
66
+ }
67
+
68
+ nil
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,52 @@
1
+ require 'concordion/utility'
2
+
3
+ module Concordion
4
+ class Verifier
5
+ include Concordion::Utility
6
+
7
+ @@ROW_REGEXP = /tr:nth\((\d+)\)/
8
+ attr_accessor :verification_variable
9
+ def initialize(concordion)
10
+ @concordion = concordion
11
+ @verification_variable = nil
12
+ @last_row = -1
13
+ end
14
+
15
+ def update_if_verify_command(cpr)
16
+ if cpr.is_verify_command?
17
+ @verification_variable = cpr.assignment
18
+ end
19
+ end
20
+
21
+ def update_verifier(idx)
22
+ return if verification_variable.nil?
23
+ arr = @concordion.get_variable(verification_variable)
24
+ index = idx < 1 ? 0 : idx - 1
25
+
26
+ value = arr[index]
27
+ @concordion.set_variable(singular(verification_variable), value)
28
+ end
29
+
30
+ def verification_variable=(value)
31
+ @verification_variable = value
32
+
33
+ unless @verification_variable.nil?
34
+ update_verifier(0)
35
+ end
36
+ end
37
+ def update_row(elem)
38
+ on_row = @@ROW_REGEXP.match(elem.css_path)
39
+ if on_row
40
+ current_row = on_row.captures[0]
41
+ if current_row != @last_row
42
+ update_verifier(current_row.to_i)
43
+ @last_row = current_row
44
+ end
45
+ else
46
+ @last_row = -1
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ module Concordion
2
+ class Writer
3
+ @@DEFAULT = "."
4
+ def initialize(output_dir = @@DEFAULT)
5
+ @output_dir = output_dir.nil? ? @@DEFAULT : output_dir
6
+ end
7
+
8
+ def write(data, filename)
9
+ create_outputs_directories_for filename
10
+ f = File.new(filename, "w")
11
+
12
+ f.puts data
13
+ f.close
14
+ end
15
+
16
+ def create_outputs_directories_for filename
17
+ directory = File.dirname filename
18
+ FileUtils.mkdir_p directory
19
+ end
20
+
21
+ def output_file_exists?(filename)
22
+ exists?(base_filename(filename))
23
+ end
24
+
25
+ def exists?(filename)
26
+ File.exists?(filename)
27
+ end
28
+
29
+ def delete_if_exists(filename)
30
+ if exists?(filename)
31
+ File.delete(filename)
32
+ end
33
+
34
+ end
35
+
36
+ def calculate_filename_and_overwrite(data, filename)
37
+ outfile = output_filename_for(filename)
38
+ delete_if_exists(outfile)
39
+ write(data, outfile)
40
+
41
+ outfile
42
+ end
43
+
44
+ def base_filename(filename)
45
+ File.join(@output_dir, filename)
46
+ end
47
+
48
+ def output_filename_for(name)
49
+ base_filename(name.sub(".html", "_test_output.html"))
50
+ end
51
+ end
52
+ end
@@ -1,23 +1,11 @@
1
- require 'concordion_utility'
2
- require 'concordion_reader'
3
- require 'concordion_parser'
4
- require 'concordion_processor'
5
- require 'concordion_parse_result'
6
- require 'concordion_test_case'
7
- require 'concordion_writer'
8
- require 'concordion_environment'
9
- require 'concordion_state'
10
- require 'concordion_css_decorator'
1
+ require 'concordion/test_methods'
11
2
  require 'test/unit'
12
3
 
13
- require 'concordion_test_methods'
14
-
15
-
16
4
  class ConcordionTestCase < Test::Unit::TestCase
17
5
 
18
- include ConcordionConfigMethods
19
- extend ConcordionConfigMethods
20
- include ConcordionInternalTestMethods
6
+ include Concordion::ConfigMethods
7
+ extend Concordion::ConfigMethods
8
+ include Concordion::InternalTestMethods
21
9
  class << self
22
10
  alias_method :original_inherited, :inherited
23
11
  end