rasta 0.1.8-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,32 @@
1
+ ---------------------------------------------------------------------------
2
+ Copyright (c) 2007, Hugh McGowan
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the names Hugh McGowan nor the names of any
16
+ other contributors to this software may be used to endorse or promote
17
+ products derived from this software without specific prior written
18
+ permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
21
+ IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
24
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ --------------------------------------------------------------------------
32
+ (based on BSD Open Source License)
data/README.txt ADDED
@@ -0,0 +1,15 @@
1
+ BUILD AND INSTALL GEM
2
+ ======================
3
+ rake install
4
+
5
+
6
+ RUNNING EXAMPLES
7
+ =================
8
+ Running simple examples using the fixture
9
+
10
+ rasta examples/rasta_fixture.xls -f examples/fixtures
11
+ rasta examples/google_search.xls -f examples/fixtures
12
+ rasta examples/crud_worksheet.xls -f examples/fixtures/crud
13
+
14
+ --help gives other options which control where and how much of the
15
+ spreadsheet to parse
data/bin/rasta ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
+ require 'rasta'
4
+ exit ::Rasta::Commandline.run
Binary file
@@ -0,0 +1,34 @@
1
+ # :stopdoc:
2
+
3
+ require 'rasta/fixture/rasta_fixture'
4
+ require 'watir'
5
+
6
+ ##
7
+ # Fixture for tests_in_column_layout.xls
8
+ class ColumnLayout
9
+
10
+ include Rasta::Fixture::RastaFixture
11
+
12
+ attr_accessor :site
13
+
14
+ ##
15
+ # Global setup.
16
+ def before_all
17
+ @@ie = Watir::IE.new
18
+ @@ie.set_fast_speed
19
+ end
20
+
21
+ ##
22
+ # Verify the browser's title is as expected for the loaded site.
23
+ def title?
24
+ @@ie.goto @site
25
+ @@ie.title
26
+ end
27
+
28
+ ##
29
+ # Global teardown.
30
+ def after_all
31
+ @@ie.close
32
+ end
33
+
34
+ end # class
@@ -0,0 +1,103 @@
1
+ # :stopdoc:
2
+
3
+ require 'rasta/fixture/rasta_fixture'
4
+ require 'watir'
5
+
6
+ ##
7
+ # Fixture for watir_example.xls
8
+ class RaceRegistration
9
+
10
+ include Rasta::Fixture::RastaFixture
11
+
12
+ attr_accessor :name, :address, :participation_type, :additional_donation,
13
+ :t_shirt_size, :car_pooling
14
+
15
+ def before_all
16
+ @@ie = Watir::IE.new
17
+ @@ie.set_fast_speed
18
+ end
19
+
20
+ def before_each
21
+ @@ie.goto(File.expand_path(File.dirname(__FILE__)) + "/../html/registration.html")
22
+ end
23
+
24
+ ##
25
+ # Requirement: The registration form should not be submitted if additional donation < 0.
26
+ # An error should be shown on the form page instead.
27
+ #--
28
+ # NOTE: The example registration app does NOT have this requirement implemented; hence,
29
+ # the negative tests based on this scenario will fail correctly.
30
+ def error?
31
+ populate_form
32
+ @@ie.button(:value, 'Submit').fire_event("onClick")
33
+ return is_error_shown_in_page?
34
+ end
35
+
36
+ ##
37
+ # Requirement: The summary page (after submitting form) should show the itemized charges.
38
+ #--
39
+ # NOTE: The expected output is defined as an Array of ints in the itemized_charges? column
40
+ # in the test spreadsheet; hence, we'll also need to return an Array of ints.
41
+ def itemized_charges?
42
+ return get_itemized_charges_from_accounting_table
43
+ end
44
+
45
+ ##
46
+ # Requirement: The summary page should show the total charges.
47
+ #--
48
+ # NOTE: total_charges? is defined as int in the spreadsheet; hence, we'll also need to
49
+ # return in int.
50
+ def total_charges?
51
+ return get_total_charges_from_accounting_table.to_i
52
+ end
53
+
54
+ ##
55
+ # Populates the form page with instance variables defined in the test spreadsheet.
56
+ def populate_form
57
+ @@ie.text_field(:name, 'name').set(@name)
58
+ @@ie.text_field(:name, 'address').set(@address)
59
+ @@ie.radio(:name, 'ptype', @participation_type).set
60
+ @@ie.text_field(:name, 'additional').set(@additional_donation.to_s)
61
+ @@ie.select_list(:name, 'tshirt').select_value(@t_shirt_size)
62
+ @@ie.checkbox(:name, 'carpooling').set if @car_pooling
63
+ end
64
+ private :populate_form
65
+
66
+ ##
67
+ # Returns true if the form page exists in the current page.
68
+ #--
69
+ # NOTE: It is assumed that (should the functionality be implemented) the form page is
70
+ # reloaded when a validation error occurs.
71
+ def is_error_shown_in_page?
72
+ @@ie.form(:id, 'test').exists?
73
+ end
74
+ private :is_error_shown_in_page?
75
+
76
+ ##
77
+ # Returns the itemized charges shown in the accounting table within the summary page
78
+ # as an Array of ints.
79
+ def get_itemized_charges_from_accounting_table
80
+ @rows = @@ie.table(:id, 'accounting_summary').row_count
81
+ last_row_with_itemized_charges = @rows - 2
82
+ itemized_charges = []
83
+ for i in 3..last_row_with_itemized_charges
84
+ itemized_charges << @@ie.table(:id, 'accounting_summary')[i][0].text.delete('$').to_i
85
+ end
86
+ itemized_charges
87
+ end
88
+ private :get_itemized_charges_from_accounting_table
89
+
90
+ ##
91
+ # Returns the total charges shown in the accounting table withing the summary page.
92
+ def get_total_charges_from_accounting_table
93
+ @@ie.table(:id, 'accounting_summary')[@rows][0].text.delete('$')
94
+ end
95
+ private :get_total_charges_from_accounting_table
96
+
97
+ ##
98
+ # Teardown.
99
+ def after_all
100
+ @@ie.close
101
+ end
102
+
103
+ end # class
@@ -0,0 +1,21 @@
1
+ require 'rasta/fixture/rasta_fixture'
2
+
3
+ class MathFunctions
4
+ include Rasta::Fixture::RastaFixture
5
+ attr_accessor :x, :y
6
+ def add
7
+ x+y
8
+ end
9
+ def subtract
10
+ x-y
11
+ end
12
+ def multiply
13
+ x*y
14
+ end
15
+ def divide
16
+ x/y
17
+ end
18
+ def x_is_even?
19
+ x % 2 == 0
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'rasta/fixture/rasta_fixture'
2
+
3
+ class StringFunctions
4
+ include Rasta::Fixture::RastaFixture
5
+ attr_accessor :phrase, :searchterm
6
+ def chop
7
+ phrase.chop
8
+ end
9
+ def reverse
10
+ phrase.reverse
11
+ end
12
+ def contains_term?
13
+ phrase[searchterm] != nil
14
+ end
15
+ def length
16
+ phrase.length
17
+ end
18
+ end
@@ -0,0 +1,62 @@
1
+ class CrudClass
2
+ def initialize
3
+ @crud_hash = {}
4
+ end
5
+
6
+ def create(isbn,title,authors,publisher)
7
+ if @crud_hash.has_key? isbn
8
+ return false
9
+ end
10
+
11
+ book = {:isbn => isbn, :title => title, :authors => authors, :publisher => publisher}
12
+ @crud_hash[isbn] = book
13
+
14
+ return true
15
+ end
16
+
17
+ def count
18
+ @crud_hash.size
19
+ end
20
+
21
+ def get_title(isbn)
22
+ if @crud_hash.has_key? isbn
23
+ @crud_hash[isbn][:title]
24
+ end
25
+ end
26
+
27
+ def get_authors(isbn)
28
+ if @crud_hash.has_key? isbn
29
+ @crud_hash[isbn][:authors]
30
+ end
31
+ end
32
+
33
+ def get_publisher(isbn)
34
+ if @crud_hash.has_key? isbn
35
+ @crud_hash[isbn][:publisher]
36
+ end
37
+ end
38
+
39
+ def update(isbn,field,value)
40
+ if @crud_hash.has_key? isbn
41
+ if field == "title"
42
+ @crud_hash[isbn][:title] = value
43
+ return true
44
+ elsif field == "authors"
45
+ @crud_hash[isbn][:authors] = value
46
+ return true
47
+ elsif field == "publisher"
48
+ @crud_hash[isbn][:publisher] = value
49
+ return true
50
+ end
51
+ end
52
+ return false
53
+ end
54
+
55
+ def delete(isbn)
56
+ if @crud_hash.has_key? isbn
57
+ @crud_hash.delete isbn
58
+ return true
59
+ end
60
+ return false
61
+ end
62
+ end
@@ -0,0 +1,37 @@
1
+ require 'rasta/fixture/rasta_fixture'
2
+ require 'examples/fixtures/crud/CrudClass'
3
+
4
+ class CrudFixture
5
+ include Rasta::Fixture::RastaFixture
6
+ attr_accessor :isbn, :title, :authors, :publisher, :field, :value
7
+
8
+ @@crud = CrudClass.new
9
+
10
+ def create
11
+ @@crud.create(isbn,title,authors,publisher)
12
+ end
13
+
14
+ def count
15
+ @@crud.count
16
+ end
17
+
18
+ def get_title
19
+ @@crud.get_title(isbn)
20
+ end
21
+
22
+ def get_authors
23
+ @@crud.get_authors(isbn)
24
+ end
25
+
26
+ def get_publisher
27
+ @@crud.get_publisher(isbn)
28
+ end
29
+
30
+ def update
31
+ @@crud.update(isbn,field,value)
32
+ end
33
+
34
+ def delete
35
+ @@crud.delete(isbn)
36
+ end
37
+ end
@@ -0,0 +1,102 @@
1
+ <!-- give the file the Make of the Web to stop the security warning -->
2
+ <!-- saved from url=(0014)about:internet -->
3
+
4
+ <html><head><title>Rasta Web Example</title></head>
5
+ <body>
6
+ <script type="text/javascript">
7
+ function process() {
8
+ var summary = ""
9
+ var charge_summary = ""
10
+ var charge_detail = ""
11
+ var participation = "Runner"
12
+ var carpool = "No"
13
+ var total = 0
14
+ var header = "<div style=\"height=25px;margin=0 1px 1px 1px;background=#006400;color=#ffffff;font-size=1.4em;\">Rasta Example - Watir</div><br>"
15
+
16
+ if (document.test.ptype[1].checked) {
17
+ participation = "Walker"
18
+ charge_detail += "<tr><td>Registration Fee (Walker)</td><td>$10</td></tr>";
19
+ total += 10;
20
+ } else {
21
+ charge_detail += "<tr><td>Registration Fee (Runner)</td><td>$15</td></tr>";
22
+ total += 15;
23
+ }
24
+ if (document.test.tshirt.value == "X-large") {
25
+ charge_detail += "<tr><td>T-Shirt (X-large)</td><td>$3</td></tr>";
26
+ total += 3;
27
+ } else if (document.test.tshirt.value == "Large") {
28
+ charge_detail += "<tr><td>T-Shirt (Large)</td><td>$2</td></tr>";
29
+ total += 2;
30
+ }
31
+ if (document.test.additional.value) {
32
+ charge_detail += "<tr><td>Additional Donation</td><td>$" + document.test.additional.value + "</td></tr>";
33
+ total += parseInt(document.test.additional.value);
34
+ <!-- This can be added to demonstrate bug in output (comment above line too)-->
35
+ <!-- total += document.test.additional.value; -->
36
+ }
37
+ if (document.test.carpooling.checked) {
38
+ carpool = "Yes";
39
+ }
40
+
41
+ summary = "<hr><b>REGISTRATION</b><hr/><br><br><table>" +
42
+ "<tr><td align=right><b>Name</td>" +
43
+ "<td>" + document.test.name.value + "</td></tr>" +
44
+ "<tr><td align=right><b>Address</th>" +
45
+ "<td>" + document.test.address.value + "</td></tr>" +
46
+ "<tr><td align=right><b>Participation Type</th>" +
47
+ "<td>" + participation + "</td></tr>" +
48
+ "<tr><td align=right><b>Shirt Size</th>" +
49
+ "<td>" + document.test.tshirt.value + "</td></tr>" +
50
+ "<tr><td align=right><b>Carpooling?</th>" +
51
+ "<td>" + carpool + "</td></tr>";
52
+ summary += "</table><br/><br/>"
53
+
54
+ charge_summary = "<hr><b>ACCOUNTING</b><hr/><br><br><table id='accounting_summary'>"
55
+ if (total != 0) {
56
+ charge_summary += "<tr><th colspan=2 align=left>Itemized Charges</th></tr>" +
57
+ "<tr><td colspan=2><hr></td></tr>" +
58
+ charge_detail +
59
+ "<tr><td colspan=2><hr></td></tr>" +
60
+ "<tr><td align=right><b>Total Charges</td><td>$" + total+ "</td></tr>"
61
+ } else {
62
+ charge_summary += "<tr><th align=right>Total Charges</th><td>$0</td></tr>"
63
+ }
64
+ charge_summary += "</table>";
65
+
66
+ document.write(header + summary + charge_summary);
67
+ document.close();
68
+ }
69
+ </script>
70
+ <div style="height=25px;margin=0 1px 1px 1px;background=#006400;color=#ffffff;font-size=1.4em;">Rasta Example - Watir</div>
71
+ <form name = "test" id="test" >
72
+ <table>
73
+ <tr>
74
+ <th align=right>Name</th>
75
+ <td><input name="name" type="text"></td>
76
+ </tr><tr>
77
+ <th align=right>Address</th>
78
+ <td><input name="address" type="text"></td>
79
+ </tr><tr>
80
+ <th align=right>Participation Type</th>
81
+ <td><input name="ptype" type="radio" value="Runner">Runner (15$)<br>
82
+ <input name="ptype" type="radio" value="Walker">Walker (10$)<br>
83
+ </td>
84
+ </tr><tr>
85
+ <th align=right>Additional Donation</th>
86
+ <td><input name="additional" type="text"></td>
87
+ </tr><tr>
88
+ <th align=right>T-Shirt Size</th>
89
+ <td><select name="tshirt">
90
+ <option value="X-large">X-large ($3 extra)
91
+ <option value="Large">Large ($2 extra)
92
+ <option value="Medium" selected>Medium
93
+ <option value="Small">Small
94
+ <option value="X-Small">X-Small
95
+ </select></td>
96
+ </tr><tr>
97
+ <td>&nbsp;</td>
98
+ <td><input name="carpooling" type="checkbox" value="unchecked"> I'm interested in carpooling
99
+ </td>
100
+ </tr></table>
101
+ <input id="submitButton" type="button" value="Submit" onclick="process()">
102
+ </form></body></html>
Binary file
Binary file
Binary file
@@ -0,0 +1,174 @@
1
+ # Extensions to RSPEC's Spec::Runner::Reporter
2
+
3
+ require 'spec/runner/reporter'
4
+
5
+ #=========================
6
+ # CHANGING TEST EXECUTION
7
+ #=========================
8
+ # We need to modify the Spec::Runner::Reporter class
9
+ # so we can use a custom formatter and pass along cell information
10
+ # to the formatter via the reporter
11
+ # (there's no built in way for the examples to pass
12
+ # data into the formatters).
13
+ #
14
+ # Additionally, we're making a change to the workflow. By default,
15
+ # rspec runs all of the examples at exit. We want to run them at
16
+ # the time we read the cell, execture one or more tests, and update that cell.
17
+ # Additionally, we don't want to report results after each call to the
18
+ # rspec runner but instead wait until we're totally done.
19
+ module Spec
20
+ module Runner
21
+ class Reporter
22
+
23
+
24
+ @@started_formatters = false
25
+
26
+ # Initialize the start time
27
+ # and set up the superclass' dump
28
+ # method to run after we're all done
29
+ def initialize_spreadsheet
30
+ @start_time = Time.new
31
+ #at_exit {original_dump}
32
+ end
33
+
34
+ # Call the formatter's method and pass in the reference
35
+ # to the spreadsheet cell so it can use it for updating
36
+ # the cell contents based on the test result
37
+ def set_current_spreadsheet_cell=(cell_reference)
38
+ formatters.each { |f| f.cell=(cell_reference) if f.methods.include?('cell=') }
39
+ end
40
+
41
+ # Stub out the dump method and call it
42
+ # after all tests are run
43
+ alias :original_dump :dump
44
+ def dump; end
45
+
46
+ # Change so we don't clear the state after each run
47
+ # and don't reset the start time
48
+ alias :original_start :start
49
+ def start(number_of_examples)
50
+
51
+ #clear [REMOVED so we keep state across tests]
52
+ #@start_time = Time.new [MOVED to initialize_spreadsheet]
53
+ if !@@started_formatters
54
+ formatters.each{|f| f.start(number_of_examples)}
55
+ @@started_formatters = true
56
+ end
57
+ end
58
+
59
+ # Expose the failure count to Rasta
60
+ def failure_count
61
+ @failures.length
62
+ end
63
+
64
+ alias :old_example_finished :example_finished
65
+ def example_finished(*args)
66
+ error = args[1]
67
+ if error
68
+ if ::Spec::Matchers.given_error
69
+ error.set_backtrace(::Spec::Matchers.given_error.backtrace)
70
+ else
71
+ error.set_backtrace(nil)
72
+ end
73
+ end
74
+ old_example_finished(*args)
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+
81
+ module Spec
82
+ module Runner
83
+ class Options
84
+ def clear_format_options
85
+ @formatters = [];
86
+ @format_options = [];
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ #=========================
93
+ # HANDLING EXCEPTIONS
94
+ #=========================
95
+ # RSpec currently throws an exception for where the test failed in
96
+ # the rspec test code. Instead, it's more useful for us to see
97
+ # the exception thrown in the proc that is called by rspec
98
+ # so we're going to provide a way to get at it
99
+
100
+ # After calling the matcher we should store the
101
+ # actual exception (not the rspec exception) for reporting
102
+ require 'spec/matchers/raise_error'
103
+ module Spec
104
+ module Matchers
105
+ class RaiseError
106
+ alias :old_matches? :matches?
107
+ def matches?(*args)
108
+ old_matches?(*args)
109
+ if @given_error
110
+ ::Spec::Matchers.given_error = @given_error
111
+ else
112
+ ::Spec::Matchers.given_error = nil
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ # Find a place to store the actal error
120
+ # that the example code can see.
121
+
122
+ require 'spec/matchers'
123
+ module Spec
124
+ module Matchers
125
+ class << self
126
+ attr_accessor :given_error
127
+ end
128
+ end
129
+ end
130
+
131
+
132
+ require 'spec/runner/formatter/html_formatter'
133
+ # Ignore empty backtraces. It would be good
134
+ # if we could show a snippet from the code that
135
+ # was called in the test fixture here. Not sure
136
+ # how hard that would be.
137
+ #
138
+ # Also show exceptions as Yellow and test
139
+ # failures as Red
140
+ module Spec
141
+ module Runner
142
+ module Formatter
143
+ class HtmlFormatter < BaseTextFormatter
144
+
145
+ def example_failed(example, counter, failure)
146
+ failure.exception.backtrace ? extra = extra_failure_content(failure) : extra = ''
147
+ failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed'
148
+ @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" unless @header_red
149
+ @header_red = true
150
+ @output.puts " <script type=\"text/javascript\">makeRed(\"example_group_#{example_group_number}\");</script>" unless @example_group_red
151
+ @example_group_red = true
152
+ move_progress
153
+ @output.puts " <dd class=\"spec #{failure_style}\">"
154
+ @output.puts " <span class=\"failed_spec_name\">#{h(example.description)}</span>"
155
+ @output.puts " <div class=\"failure\" id=\"failure_#{counter}\">"
156
+ @output.puts " <div class=\"message\"><pre>#{h(failure.exception.message)}</pre></div>" unless failure.exception.nil?
157
+ @output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(failure.exception.backtrace)}</pre></div>" unless failure.exception.nil?
158
+ @output.puts extra unless extra == ""
159
+ @output.puts " </div>"
160
+ @output.puts " </dd>"
161
+ @output.flush
162
+ end
163
+
164
+ def extra_failure_content(failure)
165
+ require 'spec/runner/formatter/snippet_extractor'
166
+ @snippet_extractor ||= SnippetExtractor.new
167
+ " <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(failure.exception)}</code></pre>"
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+