rtml 2.0.3 → 2.0.4

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.
Files changed (124) hide show
  1. data/History.txt +3 -0
  2. data/Manifest.txt +51 -13
  3. data/Rakefile +6 -1
  4. data/builtin/controllers/rtml_controller.rb +12 -1
  5. data/builtin/models/rtml/document.rb +24 -18
  6. data/builtin/models/rtml/document_model_object.rb +6 -0
  7. data/builtin/models/rtml/dom/collections/element_set.rb +6 -0
  8. data/builtin/models/rtml/dom/collections/property_set.rb +11 -0
  9. data/builtin/models/rtml/dom/element.rb +79 -27
  10. data/builtin/models/rtml/dom/frontend_element.rb +41 -20
  11. data/builtin/models/rtml/dom/property.rb +43 -26
  12. data/builtin/models/rtml/dom/screen_element.rb +13 -0
  13. data/builtin/widgets/document_variable_processing.rb +42 -18
  14. data/builtin/widgets/element_builder.rb +4 -4
  15. data/builtin/widgets/screen_variable_processing.rb +2 -2
  16. data/builtin/widgets/screen_variants.rb +31 -4
  17. data/builtin/widgets/screens.rb +13 -1
  18. data/builtin/widgets/static_content.rb +20 -6
  19. data/do_profile.rb +15 -0
  20. data/lib/extensions/action_controller/response.rb +0 -18
  21. data/lib/extensions/action_controller/routing/route_set.rb +28 -18
  22. data/lib/extensions/hpricot/doc.rb +3 -3
  23. data/lib/extensions/hpricot/elem.rb +3 -3
  24. data/lib/extensions/string.rb +2 -18
  25. data/lib/rtml.rb +0 -12
  26. data/lib/rtml/assigns.rb +32 -0
  27. data/lib/rtml/controller/document_generator.rb +9 -0
  28. data/lib/rtml/controller/render_helpers.rb +42 -18
  29. data/lib/rtml/controller/state.rb +2 -1
  30. data/lib/rtml/dependencies.rb +20 -15
  31. data/lib/rtml/dsl.rb +10 -10
  32. data/lib/rtml/environment.rb +13 -1
  33. data/lib/rtml/errors/application_error.rb +5 -0
  34. data/lib/rtml/errors/simulation_error.rb +4 -0
  35. data/lib/rtml/errors/variable_error.rb +5 -0
  36. data/lib/rtml/high_level/variable_manager.rb +11 -7
  37. data/lib/rtml/inherited_instance_variables.rb +8 -1
  38. data/lib/rtml/links.rb +17 -0
  39. data/lib/rtml/rules/dom_validation.rb +1 -0
  40. data/lib/rtml/test/builtin_variables.rb +33 -0
  41. data/lib/rtml/test/resemblance_test.rb +97 -0
  42. data/lib/rtml/test/screen.rb +126 -0
  43. data/lib/rtml/test/simulator.rb +240 -0
  44. data/lib/rtml/test/simulator_post_processors/base.rb +7 -0
  45. data/lib/rtml/test/simulator_post_processors/card_parsers.rb +32 -0
  46. data/lib/rtml/test/simulator_post_processors/receipt.rb +15 -0
  47. data/lib/rtml/test/simulator_post_processors/submit.rb +15 -0
  48. data/lib/rtml/test/spec.rb +14 -7
  49. data/lib/rtml/test/spec/matchers.rb +24 -0
  50. data/lib/rtml/test/tml_application.rb +331 -0
  51. data/lib/rtml/test/unit.rb +13 -0
  52. data/lib/rtml/test/variable_scope.rb +146 -0
  53. data/lib/rtml/version.rb +1 -1
  54. data/lib/rtml/widget.rb +26 -14
  55. data/lib/rtml/widget_core/class_methods.rb +8 -4
  56. data/lib/rtml/widget_core/widget_accessor_instance_methods.rb +6 -6
  57. data/lib/rtml/widgets.rb +22 -3
  58. data/lib/rtml_routes.rb +1 -1
  59. data/rails_generators/rtml/rtml_generator.rb +3 -0
  60. data/rails_generators/rtml/templates/db/migrate/20100513165226_add_options_to_rtml_documents.rb +9 -0
  61. data/rails_generators/rtml/templates/db/migrate/20100513165242_remove_dom_elements_mirror.rb +16 -0
  62. data/rails_generators/rtml/templates/db/migrate/20100513165249_remove_dom_properties_mirror.rb +16 -0
  63. data/rails_generators/rtml/templates/lib/tasks/rtml.rake +1 -1
  64. data/rtml.gemspec +65 -0
  65. data/spec/controllers/rtml_controller_spec.rb +1 -1
  66. data/spec/integration/post_tests_spec.rb +8 -0
  67. data/spec/lib/rtml/high_level/variable_manager_spec.rb +8 -0
  68. data/spec/lib/rtml/routes_spec.rb +23 -22
  69. data/spec/lib/rtml/test/simulator/receipt_spec.rb +18 -0
  70. data/spec/lib/rtml/test/simulator_spec.rb +185 -0
  71. data/spec/lib/rtml/test/tml_application_spec.rb +119 -0
  72. data/spec/lib/rtml/test/variable_scope_spec.rb +65 -0
  73. data/spec/lib/rtml/widget_spec.rb +1 -0
  74. data/spec/lib/rtml/widgets_spec.rb +30 -0
  75. data/spec/models/rtml/document_spec.rb +8 -0
  76. data/spec/models/rtml/dom/screen_element_spec.rb +15 -0
  77. data/spec/models/rtml/instruction_spec.rb +2 -2
  78. data/spec/rtml_action_spec.rb +25 -0
  79. data/spec/spec_helper.rb +31 -1
  80. data/spec/support/app/controllers/post_tests_controller.rb +11 -0
  81. data/spec/support/app/views/inherited/instance_variables_test/display.rtml.erb +1 -0
  82. data/spec/support/config/boot.rb +1 -0
  83. data/spec/support/config/routes.rb +3 -2
  84. data/spec/support/db/rtml_test_db.sqlite3 +0 -0
  85. data/spec/support/raw_tml/avs.tml +27 -0
  86. data/spec/support/raw_tml/document_level_events.tml +18 -0
  87. data/spec/support/raw_tml/empty_screen.tml +15 -0
  88. data/spec/support/raw_tml/enter_amount.tml +40 -0
  89. data/spec/support/raw_tml/foreign_receiver.tml +10 -0
  90. data/spec/support/raw_tml/foreign_reference.tml +10 -0
  91. data/spec/support/raw_tml/hello_world.tml +13 -0
  92. data/spec/support/raw_tml/loop_x_times.tml +39 -0
  93. data/spec/support/raw_tml/one_screen_with_setvar.tml +8 -0
  94. data/spec/support/raw_tml/receipt.tml +15 -0
  95. data/spec/support/raw_tml/simulator.tml +122 -0
  96. data/spec/support/raw_tml/tmlvar_reference.tml +34 -0
  97. data/spec/support/raw_tml/user_input.tml +47 -0
  98. data/spec/support/raw_tml/valid_document.tml +6 -0
  99. data/spec/support/rspec/example_groups.rb +1 -1
  100. data/spec/support/rspec/matchers.rb +0 -11
  101. data/spec/widgets/document_variable_processing_spec.rb +25 -39
  102. data/spec/widgets/element_builder_spec.rb +4 -0
  103. data/spec/widgets/event_listener_spec.rb +9 -0
  104. data/spec/widgets/highlevel_variable_processing_spec.rb +27 -2
  105. data/spec/widgets/screen_variable_processing_spec.rb +34 -0
  106. data/spec/widgets/screens_spec.rb +22 -0
  107. data/spec/widgets/simulator_post_processors/card_parsers_spec.rb +70 -0
  108. data/spec/widgets/simulator_post_processors/submit_spec.rb +44 -0
  109. data/tasks/stats.rake +10 -0
  110. data/test/test_rtml_generator.rb +3 -0
  111. metadata +55 -49
  112. data/builtin/widgets/subroutine.rb +0 -54
  113. data/lib/rtml/high_level/subroutine.rb +0 -22
  114. data/lib/rtml/reverse_engineering/crawler.rb +0 -58
  115. data/lib/rtml/reverse_engineering/simulator.rb +0 -269
  116. data/lib/rtml/reverse_engineering/simulator/casting.rb +0 -9
  117. data/lib/rtml/reverse_engineering/simulator/snapshot.rb +0 -18
  118. data/lib/rtml/reverse_engineering/simulator/variable_lookup.rb +0 -32
  119. data/lib/rtml/reverse_engineering/simulator/variable_value.rb +0 -105
  120. data/spec/lib/rtml/reverse_engineering/crawler_spec.rb +0 -24
  121. data/spec/lib/rtml/reverse_engineering/simulator/variable_value_spec.rb +0 -120
  122. data/spec/lib/rtml/reverse_engineering/simulator_spec.rb +0 -96
  123. data/spec/support/config/tml_dom_ruleset.rb +0 -82
  124. data/spec/widgets/subroutine_spec.rb +0 -109
@@ -1,24 +0,0 @@
1
- require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper')
2
-
3
- describe Rtml::ReverseEngineering::Crawler do
4
- context "with a prefab TML document" do
5
- before :each do
6
- subject.tml = File.read(File.join(Rtml.root, "spec/support/raw_tml/valid_document.tml"))
7
- end
8
-
9
- it "should visit #init and then #main" do
10
- subject.visit "#init"
11
- subject.current_screen.should == "main"
12
- end
13
- end
14
-
15
- context "with a missing action" do
16
- before :each do
17
- subject.visit "/rtml/missing_action.rtml?ignore_state=true" #"/rtml-2.0.0/missing_action.tml?ignore_state=true"
18
- end
19
-
20
- it "should pause at #rescue" do
21
- subject.current_screen.should == "rescue"
22
- end
23
- end
24
- end
@@ -1,120 +0,0 @@
1
- require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper')
2
-
3
- def varval(setvar, type, vars = {})
4
- Rtml::ReverseEngineering::Simulator::VariableValue.new(setvar, vars, {setvar['name'] => type})
5
- end
6
-
7
- describe Rtml::ReverseEngineering::Simulator::VariableValue do
8
- it "should resolve variable names in operands" do
9
- var = varval(Hpricot::XML("<setvar name='count' lo='tmlvar:start' />").root, :integer, :start => 0)
10
- var.send(:lo).should == 0
11
- end
12
-
13
- context "with an assignment" do
14
- it "should == an operation with same result" do
15
- varval(Hpricot::XML("<setvar name='count' lo='5' />").root, :integer).should ==
16
- varval(Hpricot::XML("<setvar name='count' lo='2' op='plus' ro='3' />").root, :integer)
17
- end
18
-
19
- context "given an integer" do
20
- before :each do
21
- @subject = varval(Hpricot::XML("<setvar name='count' lo='5' />").root, :integer)
22
- end
23
-
24
- it "should set value to :lo" do
25
- subject.value.should == 5
26
- end
27
- end
28
-
29
- context "given a string" do
30
- before :each do
31
- @subject = varval(Hpricot::XML("<setvar name='count' lo='5' />").root, :string)
32
- end
33
-
34
- it "should set value to :lo" do
35
- subject.value.should == '5'
36
- end
37
- end
38
-
39
- context "given an opaque" do
40
- before :each do
41
- @subject = varval(Hpricot::XML("<setvar name='count' lo='5' />").root, :opaque)
42
- end
43
-
44
- it "should set value to :lo" do
45
- subject.value.should == '5'
46
- end
47
- end
48
-
49
- context "given a date" do
50
- before :each do
51
- @subject = varval(Hpricot::XML("<setvar name='count' lo='5/5/5' />").root, :date)
52
- end
53
-
54
- it "should set value to :lo" do
55
- subject.value.should == "5/5/5"
56
- end
57
- end
58
- end
59
-
60
- context "with an operation" do
61
- it "should resolve operands" do
62
- var = varval(Hpricot::XML("<setvar name='count' lo='tmlvar:count' op='plus' ro='1' />").root, :integer,
63
- 'count' => varval(Hpricot::XML("<setvar name='count' lo='2' />").root, :integer))
64
- var.value.should == 3
65
- end
66
-
67
- it "should == an assignment with same result" do
68
- varval(Hpricot::XML("<setvar name='count' lo='2' op='plus' ro='3' />").root, :integer).should ==
69
- varval(Hpricot::XML("<setvar name='count' lo='5' />").root, :integer)
70
- end
71
-
72
- context "given an integer" do
73
- it "should set value to :lo plus :ro" do
74
- varval(Hpricot::XML("<setvar name='count' lo='2' op='plus' ro='3' />").root, :integer).value.should == 5
75
- end
76
-
77
- it "should set value to :lo minus :ro" do
78
- varval(Hpricot::XML("<setvar name='count' lo='7' op='minus' ro='2' />").root, :integer).value.should == 5
79
- end
80
- end
81
-
82
- context "given an opaque" do
83
- it "should raise an error because no operations are possible" do
84
- proc do
85
- varval(Hpricot::XML("<setvar name='count' lo='7' op='minus' ro='2' />").root, :opaque)
86
- end.should raise_error(Rtml::Errors::InvalidOperation)
87
- end
88
- end
89
-
90
- context "given a string" do
91
- it "should set value to :lo plus :ro" do
92
- varval(Hpricot::XML("<setvar name='count' lo='3' op='plus' ro='2' />").root, :string).value.should == "32"
93
- end
94
-
95
- it "should set value to :lo minus :ro" do
96
- varval(Hpricot::XML("<setvar name='count' lo='72' op='minus' ro='1' />").root, :string).value.should == "7"
97
- end
98
-
99
- it "should set value to :lo format :ro" #do
100
- #varval(Hpricot::XML("<setvar name='count' lo='7' op='format' ro='c' />").root, :string)
101
- #end
102
- end
103
-
104
- context "given a string list" do
105
- it "should set value to :lo item :ro" do
106
- varval(Hpricot::XML("<setvar name='count' lo='1;2;3;4' op='item' ro='1' />").root, :string).value.should == "2"
107
- end
108
-
109
- it "should set value to :lo number :ro" do
110
- varval(Hpricot::XML("<setvar name='count' lo='1;2;3;4' op='number' />").root, :integer).value.should == 4
111
- end
112
- end
113
-
114
- context "given a date" do
115
- it "should set value to :lo plus :ro"
116
-
117
- it "should set value to :lo minus :ro"
118
- end
119
- end
120
- end
@@ -1,96 +0,0 @@
1
- require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper')
2
-
3
- describe Rtml::ReverseEngineering::Simulator do
4
- context "with a valid TML document" do
5
- before :each do
6
- subject.tml = File.read(File.join(Rtml.root, "spec/support/raw_tml/valid_document.tml"))
7
- end
8
-
9
- it "should allow visiting without interaction (ignoring hotkeys, hrefs, etc)" do
10
- subject.visit(:nointerstart).should == 'nointerdone'
11
- end
12
-
13
- context "with preassigned variables" do
14
- before :each do
15
- subject.set :counter => 4
16
- end
17
-
18
- it "should use its values" do
19
- subject.analyze(:variantcheck, :variantdone).should == :completion
20
- subject.route.should == ['variantcheck', 'variantdone']
21
- end
22
- end
23
-
24
- it "should calculate #route accurately" do
25
- subject.analyze(:init, :main)
26
- subject.route.should == ["init", "main"]
27
- end
28
-
29
- it "should follow variants" do
30
- subject.analyze(:variantstart, :variantdone).should == :completion
31
- end
32
-
33
- it "should auto-follow variants with hotkeys" do
34
- subject.analyze(:variantstart, :varianthk).should == :completion
35
- end
36
-
37
- it "should auto-follow variants with timeouts" do
38
- subject.analyze(:variantstart, :variantto).should == :completion
39
- end
40
-
41
- it "should auto-follow hrefs" do
42
- subject.analyze(:variantstart, :variantcancl).should == :completion
43
- end
44
-
45
- it "should return :completion when given a valid route" do
46
- subject.analyze(:init, :main).should == :completion
47
- end
48
-
49
- it "should return :circular when given a circular document and invalid route" do
50
- subject.analyze(:init, :main, :dead_start).should == :circular
51
- end
52
-
53
- it "should return :assertion when it results in a visit to the #assert screen" do
54
- subject.analyze(:assert_start, :dead_start).should == :assertion
55
- end
56
-
57
- it "should return :dead_end when route ends before completion is met" do
58
- subject.analyze(:dead_start, :dead_end, :dead_start).should == :dead_end
59
- end
60
-
61
- it "should raise an error when given a nonexistent screen ID" do
62
- proc { subject.analyze :idle }.should raise_error(Rtml::Errors::ScreenNotFound)
63
- end
64
- end
65
-
66
-
67
- context "with an invalid XML document" do
68
- # TODO: Consider moving entirely to rexml?
69
- it "should raise an error" do
70
- pending "migration from hpricot to rexml"
71
- proc { subject.tml = "<malformedRoot>" }.should raise_error
72
- end
73
- end
74
-
75
- context "with an invalid TML document" do
76
- it "should raise an error when given" do
77
- proc do
78
- subject.tml = <<-end_tml
79
- <?xml version="1.0" encoding="ISO-8859-1"?>
80
- <tml xmlns="http://www.ingenico.co.uk/tml" cache="deny">
81
- <head />
82
-
83
- <screen id="main" cancel="emb://embedded.tml">
84
-
85
- <!--error here--> <screen />
86
-
87
- <display>
88
- <h1>Hello, World!</h1>
89
- </display>
90
- </screen>
91
- </tml>
92
- end_tml
93
- end.should raise_error(Rtml::Errors::RulesViolationError)
94
- end
95
- end
96
- end
@@ -1,82 +0,0 @@
1
- # This file quite literally tells RTML the "rules" governing the TML document structure. You could modify this file
2
- # if you are directly inventing a TML-ish language of your own, but otherwise it's probably best to leave this file
3
- # as it is, or else you are at risk of generating invalid TML.
4
- #
5
- # Was going to store all of this in the DB, but decided it's probably better for everyone to just static load it.
6
- # Might revisit this someday, but for now, whatever.
7
-
8
- tags %W{
9
- a baddata base br call_func card col colgroup dd defaults display div dl dt econn error form getvar h1 h2 h3 h4 h5
10
- h6 head hr img input layout li link log logdcl logrec next ol p pinentry postvar pre print prompt screen setvar span
11
- strtemplate submit submit_log table tbody td textarea tfoot tform th thead tml tmlpost tr ul vardcl variant
12
- }
13
-
14
- root :tml
15
- order do
16
- head :base, :link, :defaults, :error
17
- logdcl :vardcl, :layout
18
- screen :setvar, :strtemplate, :logrec, :next, :error, :call_func, :display, :print, :submit, :tform
19
- submit :econn, :getvar, :submit_log
20
- table :col, :colgroup, :thead, :tfoot, :tbody, :tr
21
- tform :baddata, :card, :prompt, :pinentry
22
- tml :head, :vardcl, :logdcl, :screen
23
- end
24
- children :layout, all_tag_names - [:form]
25
- children :print, %W{div dl h1 h2 h3 h4 h5 h6 hr img log ol p pre table ul form}
26
- children :display, %W{a br div dl form getvar h1 h2 h3 h4 h5 h6 hr img input log ol p pre span table textarea ul}
27
- children :p, %W{a br getvar input span textarea}
28
- children do
29
- a :img
30
- baddata %W{a br div dl h1 h2 h3 h4 h5 h6 hr img getvar ol p pre span table ul}
31
- colgroup :col
32
- dd %W{a br span getvar input textarea div dl h1 h2 h3 h4 h5 h6 hr img ol p pre table ul form}
33
- div %W{a br div dl form getvar h1 h2 h3 h4 h5 h6 hr img input ol p pre span table textarea ul}
34
- dl %W{dt dd}, :minimum => 1 #dt+ dd+
35
- dt %W{a br div dl form getvar h1 h2 h3 h4 h5 h6 hr img input ol p pre span table textarea ul}
36
- econn :variant #variant*
37
- error :variant #variant*
38
- form %W{div dl h1 h2 h3 h4 h5 h6 hr img ol p pre table ul input textarea}
39
- h1 %W{a br getvar input span textarea}
40
- h2 %W{a br getvar input span textarea}
41
- h3 %W{a br getvar input span textarea}
42
- h4 %W{a br getvar input span textarea}
43
- h5 %W{a br getvar input span textarea}
44
- h6 %W{a br getvar input span textarea}
45
- head %W{base defaults error}, :minimum => 0, :maximum => 1 #base?, defaults?, error?
46
- head :link # link*
47
- input :baddata, :minimum => 0, :maximum => 1
48
- li %W{a br span getvar input textarea div dl h1 h2 h3 h4 h5 h6 hr img ol p pre table ul form}
49
- log %W{vardcl layout}
50
- send :next, %W{variant}
51
- ol :li
52
- pre %W{a br getvar input span textarea}
53
- prompt %W{div dl h1 h2 h3 h4 h5 h6 hr img ol p pre table ul}
54
- screen %W{setvar strtemplate logrec}
55
- screen %W{next error call_func display print submit tform}, :maximum => 1
56
- span %W{a br span getvar input textarea}
57
- strtemplate :getvar, :minimum => 0, :maximum => 9
58
- submit :econn, :maximum => 1
59
- submit %W{getvar submit_log}
60
- table %W{col colgroup tbody tr}
61
- table %W{thead tfoot}, :maximum => 1
62
- tbody :tr
63
- td %W{a br span getvar input textarea div dl h1 h2 h3 h4 h5 h6 hr img ol p pre table ul form dd display li print td
64
- th}
65
- textarea :baddata, :maximum => 1
66
- tfoot :tr
67
- tform %W{baddata prompt}, :maximum => 1
68
- tform :card
69
- tform :pinentry, :maximum => 1
70
- th %W{a br span getvar input textarea div dl h1 h2 h3 h4 h5 h6 hr img ol p pre table ul form dd display li print td
71
- th}
72
- thead :tr
73
- tml :head, :maximum => 1
74
- tml %W{vardcl logdcl screen}
75
- tmlpost :postvar
76
- tr :th, :td
77
- ul :li
78
- variant :li
79
- end
80
-
81
- freeze # prevent further modification of the rules
82
-
@@ -1,109 +0,0 @@
1
- require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper')
2
-
3
- describe Rtml::Widgets::Subroutine do
4
- before :each do
5
- @doc = Rtml::Document.new
6
- @doc.boolean :condition_var
7
- @doc.boolean :txn_is_emv
8
-
9
- @doc.subroutine :return_true do |args|
10
- return true
11
- end
12
-
13
- @doc.subroutine :return_false do |args|
14
- return false
15
- end
16
-
17
- @doc.subroutine :check_is_emv do |args|
18
- _if(tvars[:txn_is_emv] == true) { return true }
19
- _else { return false }
20
- end
21
-
22
- @doc.subroutine :check_condition do |args|
23
- tvars[args[:name]] = args[:value]
24
- _if(tvars[args[:name]] == true) { goto :condition_is_true }
25
- _else { goto :condition_is_untrue }
26
- end
27
- end
28
-
29
- it "should declare the subroutine return variable" do
30
- # the var isn't created until a sub is called.
31
- @doc.screen :i do call(:return_true) end
32
- assert @doc.variable?(:rtml_sub_return_val)
33
- end
34
-
35
- it "should be able to query whether a symbol or string is a subroutine name" do
36
- assert @doc.subroutine?("return_true")
37
- assert @doc.subroutine?(:return_false)
38
- assert @doc.subroutine?(:check_condition)
39
- assert !@doc.subroutine?(:not_a_sub)
40
- assert !@doc.subroutine?('not_a_sub')
41
-
42
- # and now from a child...
43
- assert_raises RuntimeError, "subroutine :return_true not found" do
44
- @doc.screen :some_screen do
45
- raise if subroutine?("return_true")
46
- end
47
- end
48
- end
49
-
50
- it "should be able to transform the document directly" do
51
- @doc.screen :condition_check_screen do
52
- call :check_condition, :name => :condition_var, :value => true
53
- end
54
-
55
- #puts @tml_docs.to_tml
56
- end
57
-
58
- # add your own tests here
59
- it "should contain 2 subroutines called return_true and return_false" do
60
- #assert_length 4, @tml_docs.subroutines
61
- assert @doc.subroutines.keys.include?('return_true')
62
- assert @doc.subroutines.keys.include?('return_false')
63
- end
64
-
65
- it "should raise NoMethodError if subroutine does not exist" do
66
- assert_raises NoMethodError do
67
- @doc.screen(:a_screen).call :no_method
68
- end
69
- end
70
-
71
- it "should be able to call a subroutine and get the correct response" do
72
- @scr = @doc.screen :a_screen
73
- assert_equal ["tmlvar:rtml_sub_return_val", "equal", "tmlvar:rtml_sub_return_val"],
74
- @scr.call(:return_true) == "tmlvar:rtml_sub_return_val"
75
- assert_not_nil(@var = (@scr / "setvar[name=rtml_sub_return_val]").first)
76
- assert_equal true, @var.property('lo')
77
- @var.to_tml.should be_valid_tml
78
- assert((tml = @scr.to_tml) =~ /setvar[^>]+?lo=["']1["']/, tml)
79
-
80
- assert_equal ["tmlvar:rtml_sub_return_val", "equal", "tmlvar:rtml_sub_return_val"],
81
- @scr.call(:return_false) == "tmlvar:rtml_sub_return_val"
82
- assert_not_nil(@var = (@scr / "setvar[name=rtml_sub_return_val]").last)
83
- assert_equal false, @var.property('lo')
84
- @var.to_tml.should be_valid_tml
85
- assert((tml = @scr.to_tml) =~ /setvar[^>]+?lo=["']0["']/, tml)
86
-
87
- # make sure it generated setvars -- why is this necessary??
88
- # update - turns out to be an artifact from reordering elements in ElementBuilder#rebuild_invalid_elements.
89
- # Resolved, by simply re-adding the same element instead of building an all new one.
90
- assert @doc.to_tml =~ /setvar[^>]+?lo=["']1["']/, "element missing - check ElementBuilder#rebuild_invalid_elements"
91
- assert @doc.to_tml =~ /setvar[^>]+?lo=["']0["']/, "element missing - check ElementBuilder#rebuild_invalid_elements"
92
- end
93
-
94
- it "should be able to conditionally respond to subroutine results" do
95
- @doc.string :ret
96
- @doc.screen :get_return_value, :check_return_value do
97
- tvars[:ret] = call(:check_is_emv)
98
- end
99
-
100
- @doc.screen :check_return_value do
101
- _if(tvars[:ret] == true) { goto :condition_was_true }
102
- _elsif(tvars[:ret] == false) { goto :condition_was_false }
103
- _else { goto :condition_was_not_boolean }
104
- end
105
-
106
- # TODO: Above produces the expected TML result. Assert that this is true, and then start playing with syntax.
107
- #puts @tml_docs.to_tml
108
- end
109
- end