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/lib/rasta.rb ADDED
@@ -0,0 +1,198 @@
1
+ =begin
2
+ Copyright © 2008, Hugh McGowan. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the names Hugh McGowan nor the names of any
15
+ other contributors to this software may be used to endorse or promote
16
+ products derived from this software without specific prior written
17
+ permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS
20
+ IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
23
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ (based on BSD Open Source License)
32
+ =end
33
+
34
+ module Rasta
35
+ require 'optparse'
36
+ require 'singleton'
37
+
38
+ class Configuration
39
+ include Singleton
40
+ OPTIONS = {
41
+ :fixture_path => nil, # Location of your test fixtures
42
+ :results_path => 'rasta_test_results', # Where to place results
43
+ :module => nil, # Only look here for fixutre name space
44
+ :require => [], # special case if you load your own libs (like from a module)
45
+ :visible => true, # Visibility of the spreadsheet during the run
46
+ :continue => false, # Continue an aborted run or continue a run
47
+ :pagecount => 0, # Number of pages to process
48
+ :recordcount => 0, # Number of records to process
49
+ :showversion => false, # flag to track if we just show the version and exit
50
+ :help => nil,
51
+ :result_index => 0, # index of the result file
52
+ :spreadsheets => nil, # location of spreadsheet to run
53
+ }
54
+ attr_accessor *OPTIONS.keys
55
+
56
+ def initialize
57
+ read(OPTIONS) # Set detault values
58
+ end
59
+
60
+ # Add warning to logs if an unsupported attribute is requested
61
+ def method_missing(method, *args)
62
+ method = method.to_s.gsub('=','')
63
+ puts("Warning: Configuration attribute '#{method}' is not a recognized option")
64
+ end
65
+
66
+ # Given an option hash, set the attributes in this class
67
+ def read(opts)
68
+ opts.each_key do |key|
69
+ eval("self.#{key} = opts[key]")
70
+ end
71
+ end
72
+
73
+ def raw_options
74
+ opts = {}
75
+ OPTIONS.each_key do |key|
76
+ opts[key] = eval("self.#{key}")
77
+ end
78
+ return opts
79
+ end
80
+
81
+ def fixture_path=(x)
82
+ @fixture_path = x
83
+ @fixture_path.gsub("\\","/") if x
84
+ end
85
+ end
86
+
87
+ class Commandline
88
+ class << self
89
+
90
+ # This is the main way to run the rasta commandline from a binary
91
+ def run
92
+ parse_options
93
+ run_test_fixtures
94
+ end
95
+
96
+ # This is how you could run it if you were grabbing the define_options into your options
97
+ # and running through a wrapper. Just be careful not to use the same flags used by rasta
98
+ # in define_options or you could stomp on each other's options
99
+ def run_from_wrapper
100
+ get_spreadsheets
101
+ run_test_fixtures
102
+ end
103
+
104
+ # These are the rasta-specific commandline options. You can call this method
105
+ # directly if you want to merge them in with your own option wrapper
106
+ def define_options(cli)
107
+ config = Rasta::Configuration.instance
108
+ cli.on('-f','--fixture-path PATH', 'Location of test fixtures') { |config.fixture_path|}
109
+ cli.on('-r','--results-path PATH', 'Location of test results') { |config.results_path|}
110
+ cli.on('-n','--namespace MODULE', 'Limit test fixture scope to this namespace') { |config.module|}
111
+ cli.on('-c','--continue BOOKMARK', 'Continue spreadsheet from bookmark') { |config.continue|; config.continue = true if !config.continue}
112
+ cli.on('-p','--pagecount NUMPAGES','Number of pages to process') { |x| config.pagecount = x.to_i}
113
+ cli.on('--recordcount NUMRECORDS','Number of records to process') { |x| config.recordcount = x.to_i}
114
+ cli.on('--hide', 'Hide spreadsheet during run') { config.visible = false }
115
+ cli.on('-v','--version', 'Show version') { config.showversion = true }
116
+ cli.on('--help', 'Show the detailed help and quit') { config.help = true }
117
+ end
118
+
119
+ # Parse the commandline options and populate the
120
+ # singleton Configuration class
121
+ def parse_options
122
+ parser = OptionParser.new do |cli|
123
+ cli.banner += " [file(s) ...]"
124
+ define_options(cli)
125
+ end
126
+
127
+ # Parse the commandline args
128
+ begin
129
+ parser.parse!(ARGV)
130
+ rescue => e
131
+ puts parser.help
132
+ puts
133
+ puts e
134
+ exit
135
+ end
136
+ config = Rasta::Configuration.instance
137
+ if config.help
138
+ puts parser.help
139
+ exit
140
+ elsif config.showversion
141
+ require 'rasta/version'
142
+ puts Rasta::VERSION::DESCRIPTION
143
+ exit
144
+ end
145
+
146
+ # After getting the options, just the spreadsheet should be left
147
+ get_spreadsheets
148
+
149
+ # Report all errors together
150
+ errmsg = String.new
151
+ errmsg = "No spreadsheet defined\n" if !config.spreadsheets
152
+ errmsg += "No fixture_path defined\n" if !config.fixture_path
153
+ if ! errmsg.empty?
154
+ puts parser.help
155
+ puts
156
+ puts errmsg
157
+ exit
158
+ end
159
+
160
+ end
161
+
162
+ def get_spreadsheets
163
+ config = Rasta::Configuration.instance
164
+ ARGV.options = nil
165
+ config.spreadsheets = []
166
+ while file = ARGV.shift do
167
+ config.spreadsheets << file
168
+ end
169
+ end
170
+
171
+ def run_test_fixtures
172
+ start_interrupt_handler
173
+
174
+ # This is a workaround for watir. If we try to use Modal Dialogs
175
+ # and we load win32OLE before watir, we get an exception, even if using
176
+ # the supported version of Ruby (1.8.2)
177
+ # See http://jira.openqa.org/browse/WTR-2 for details.
178
+ # Also, this needs to be after we parse our options because watir
179
+ # uses some of the same options and will slurp them up...
180
+ require 'watir' if RUBY_VERSION == "1.8.2"
181
+
182
+ # Run the test fixtures
183
+ config = Rasta::Configuration.instance
184
+ require 'rasta/fixture_runner'
185
+ runner = Rasta::Fixture::FixtureRunner.new
186
+ config.spreadsheets.each { |file| runner.add(file) }
187
+ runner.execute
188
+ puts
189
+ puts "Test results are available in #{Configuration.instance.results_path}"
190
+ exit
191
+ end
192
+
193
+ def start_interrupt_handler
194
+ trap "SIGINT", proc { puts "User Interrupt!!!\nExiting..." ; exit 1}
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,9 @@
1
+ require 'lib/rasta/fixture/rasta_fixture'
2
+
3
+ class RastaTestFixture
4
+ include Rasta::Fixture::RastaFixture
5
+ attr_accessor :a, :b
6
+ def show_attributes
7
+ [a,b]
8
+ end
9
+ end
Binary file
@@ -0,0 +1,138 @@
1
+ TOPDIR = File.join(File.dirname(__FILE__), '..')
2
+ $LOAD_PATH.unshift File.expand_path(TOPDIR)
3
+
4
+ require 'spec'
5
+ require 'lib/rasta/spreadsheet'
6
+
7
+ TESTFILE = TOPDIR + '/test/spreadsheets/spreadsheet_parsing.xls'
8
+
9
+ describe 'Bookmark', :shared => true do
10
+ after(:each) do
11
+ Rasta::Spreadsheet::Excel.instance.continue = false
12
+ end
13
+ end
14
+
15
+ describe 'Bookmarks' do
16
+ it_should_behave_like 'Bookmark'
17
+
18
+ it 'should fail if booktitle not specified' do
19
+ lambda { bookmark = Rasta::Spreadsheet::Bookmark.new() }.should raise_error
20
+ end
21
+
22
+ it 'should not continue from invalid bookmark' do
23
+ lambda {bookmark = Rasta::Spreadsheet::Bookmark.new() }.should raise_error
24
+ end
25
+
26
+ it 'should support continue with page name only' do
27
+ bookmark = Rasta::Spreadsheet::Bookmark.new('PageName')
28
+ bookmark.page.should == 'PageName'
29
+ bookmark.record.should be_nil
30
+ end
31
+
32
+ it 'should support continue with page name and record column' do
33
+ bookmark = Rasta::Spreadsheet::Bookmark.new('PageName[R]')
34
+ bookmark.page.should == 'PageName'
35
+ bookmark.record.should == 'R'
36
+ end
37
+
38
+ it 'should downcase record column in continuation' do
39
+ bookmark = Rasta::Spreadsheet::Bookmark.new('PageName[r]')
40
+ bookmark.page.should == 'PageName'
41
+ bookmark.record.should == 'R'
42
+ end
43
+
44
+ it 'should support continue with page name and record row' do
45
+ bookmark = Rasta::Spreadsheet::Bookmark.new('PageName[2]')
46
+ bookmark.page.should == 'PageName'
47
+ bookmark.record.should == '2'
48
+ end
49
+
50
+
51
+ end
52
+
53
+ describe 'SpreadsheetTab', :shared => true do
54
+ before(:each) do
55
+ @excel = Rasta::Spreadsheet::Excel.instance
56
+ @excel.continue = false
57
+ @excel.pagecount = 0
58
+ @book = Rasta::Spreadsheet::Book.new(TESTFILE)
59
+ end
60
+ after(:each) do
61
+ Rasta::Spreadsheet::Excel.instance.cleanup
62
+ @book.bookmark = nil
63
+ end
64
+ end
65
+
66
+ describe 'Continuations' do
67
+ it_should_behave_like 'SpreadsheetTab'
68
+
69
+ it "should be able to continue from bookmark in 'column' style for 1 pagecount length" do
70
+ expected_records = [[4, 2], [5, 0], [3.0, 4.0]]
71
+ @book.bookmark = Rasta::Spreadsheet::Bookmark.new('RowStyle.1[E]')
72
+ @excel.continue = 'RowStyle.1'
73
+ @excel.pagecount = 1
74
+ @book.each do |sheet|
75
+ sheet.name.should == 'RowStyle.1'
76
+ sheet.dump.should == expected_records
77
+ end
78
+ end
79
+
80
+ it "should be able to continue from bookmark in 'row' style for 1 pagecount length" do
81
+ expected_records = [[4, 2], [5, 0], [3.0, 4.0]]
82
+ @book.bookmark = Rasta::Spreadsheet::Bookmark.new('ColStyle.3[5]')
83
+ @excel.continue = true
84
+ @excel.pagecount = 1
85
+ @book.each do |sheet|
86
+ sheet.name.should == 'ColStyle.3'
87
+ sheet.dump.should == expected_records
88
+ end
89
+ end
90
+
91
+ it "should be able to continue from bookmark in 'column' style for 1 recordcount length" do
92
+ expected_records = [[4, 2], [5, 0]]
93
+ @book.bookmark = Rasta::Spreadsheet::Bookmark.new('RowStyle.1[E]')
94
+ @excel.continue = 'RowStyle.1'
95
+ @excel.recordcount = 2
96
+ @book.each do |sheet|
97
+ sheet.name.should == 'RowStyle.1'
98
+ sheet.dump.should == expected_records
99
+ end
100
+ end
101
+
102
+ it "should be able to continue from bookmark in 'row' style for 1 recordcount length" do
103
+ expected_records = [[4, 2]]
104
+ @book.bookmark = Rasta::Spreadsheet::Bookmark.new('ColStyle.3[5]')
105
+ @excel.continue = true
106
+ @excel.recordcount = 1
107
+ @book.each do |sheet|
108
+ sheet.name.should == 'ColStyle.3'
109
+ sheet.dump.should == expected_records
110
+ end
111
+ end
112
+
113
+ it 'should be able to continue from bookmark for multiple pages count' do
114
+ expected_sheet_names = ['ColStyle.4', 'RowStyle.1']
115
+ expected_records = [[[3.0, 4.0]],
116
+ [[1.0, 2.0], [2, 1], [3, 0], [4, 2], [5, 0], [3.0, 4.0]]]
117
+ @book.bookmark = Rasta::Spreadsheet::Bookmark.new('ColStyle.4[7]')
118
+ @excel.continue = true
119
+ @excel.pagecount = 1
120
+ sheet_number = 0
121
+ @book.each do |sheet|
122
+ sheet.name.should == expected_sheet_names[sheet_number]
123
+ sheet.dump.should == expected_records[sheet_number]
124
+ sheet_number += 1
125
+ end
126
+ end
127
+
128
+ it "should be able to continue from bookmark containing comment" do
129
+ expected_records = [[4, 2], [5, 0], [3.0, 4.0]]
130
+ @book.bookmark = Rasta::Spreadsheet::Bookmark.new('RowStyle.1#commented[E]')
131
+ @excel.continue = true
132
+ @excel.pagecount = 1
133
+ @book.each do |sheet|
134
+ sheet.name.should == 'RowStyle.1'
135
+ sheet.dump.should == expected_records
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,66 @@
1
+ TOPDIR = File.join(File.dirname(__FILE__), '..')
2
+ $LOAD_PATH.unshift File.expand_path(TOPDIR)
3
+ require 'spec'
4
+
5
+
6
+ #================
7
+ # base_fixture
8
+ #================
9
+
10
+ require 'lib/rasta'
11
+
12
+ require TOPDIR + '/lib/rasta/fixture/base_fixture'
13
+ describe "Metrics" do
14
+ it "should increment :attribute_count" do
15
+ m = Rasta::Fixture::BaseFixture::Metrics.new
16
+ m.inc(:attribute_count)
17
+ m.attribute_count.should == 1
18
+ end
19
+ it "should increment :method_count" do
20
+ m = Rasta::Fixture::BaseFixture::Metrics.new
21
+ m.inc(:method_count)
22
+ m.method_count.should == 1
23
+ end
24
+ it "should increment :attribute_count" do
25
+ m = Rasta::Fixture::BaseFixture::Metrics.new
26
+ m.inc(:record_count)
27
+ m.record_count.should == 1
28
+ end
29
+ end
30
+
31
+ #================
32
+ # rasta_fixture
33
+ #================
34
+
35
+ TESTFILE = TOPDIR + '/test/spreadsheets/rasta_fixture.xls'
36
+ require TOPDIR + '/test/fixtures/RastaTestFixture'
37
+ require 'lib/rasta/spreadsheet'
38
+
39
+ describe 'SpreadsheetTab', :shared => true do
40
+ before(:all) do
41
+ @book = Rasta::Spreadsheet::Book.new(TESTFILE)
42
+ @sheet = nil
43
+ end
44
+ after(:all) do
45
+ Rasta::Spreadsheet::Excel.instance.cleanup
46
+ end
47
+
48
+ end
49
+
50
+ #describe "Test Fixture Attributes" do
51
+ # it_should_behave_like 'SpreadsheetTab'
52
+ # before(:all) do
53
+ # @sheetname = @book['TestFixture#1']
54
+ # @fixture = RastaTestFixture.new
55
+ # @fixture.instance_eval {@sheet = @sheetname}
56
+ # @fixture.instance_eval {@metrics = Metrics.new}
57
+ # end
58
+ # it "should reset attributes between records" do
59
+ # @fixture.call_fixture_attribute('a','test')
60
+ # @fixture.clear_attributes
61
+ # @fixture.a.should be_nil
62
+ # end
63
+ #end
64
+
65
+ #describe "Test Fixture Methods" do
66
+ #end