bret-watircraft 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/BUGS.txt +11 -0
- data/History.txt +209 -0
- data/Manifest.txt +103 -0
- data/README.rdoc +75 -0
- data/VERSION.yml +4 -0
- data/app_generators/watircraft/USAGE +11 -0
- data/app_generators/watircraft/templates/config.yml.erb +3 -0
- data/app_generators/watircraft/templates/feature_helper.rb +12 -0
- data/app_generators/watircraft/templates/initialize.rb.erb +10 -0
- data/app_generators/watircraft/templates/rakefile.rb +3 -0
- data/app_generators/watircraft/templates/script/console +5 -0
- data/app_generators/watircraft/templates/script/console.cmd +1 -0
- data/app_generators/watircraft/templates/site_start.rb.erb +12 -0
- data/app_generators/watircraft/templates/spec_helper.rb +9 -0
- data/app_generators/watircraft/templates/spec_initialize.rb +16 -0
- data/app_generators/watircraft/templates/world.rb +12 -0
- data/app_generators/watircraft/watircraft_generator.rb +108 -0
- data/bin/watircraft +17 -0
- data/lib/extensions/array.rb +10 -0
- data/lib/extensions/hash.rb +5 -0
- data/lib/extensions/object.rb +24 -0
- data/lib/extensions/string.rb +17 -0
- data/lib/extensions/watir.rb +41 -0
- data/lib/taza/browser.rb +45 -0
- data/lib/taza/entity.rb +34 -0
- data/lib/taza/fixture.rb +66 -0
- data/lib/taza/flow.rb +40 -0
- data/lib/taza/page.rb +259 -0
- data/lib/taza/settings.rb +80 -0
- data/lib/taza/site.rb +227 -0
- data/lib/taza/tasks.rb +30 -0
- data/lib/taza.rb +35 -0
- data/lib/watircraft/generator_helper.rb +27 -0
- data/lib/watircraft/table.rb +56 -0
- data/lib/watircraft/version.rb +3 -0
- data/lib/watircraft.rb +1 -0
- data/spec/array_spec.rb +16 -0
- data/spec/browser_spec.rb +68 -0
- data/spec/entity_spec.rb +9 -0
- data/spec/fake_table.rb +34 -0
- data/spec/fixture_spec.rb +34 -0
- data/spec/fixtures_spec.rb +21 -0
- data/spec/hash_spec.rb +12 -0
- data/spec/object_spec.rb +29 -0
- data/spec/page_generator_spec.rb +111 -0
- data/spec/page_spec.rb +342 -0
- data/spec/project_generator_spec.rb +103 -0
- data/spec/sandbox/config/config.yml +1 -0
- data/spec/sandbox/config/environments.yml +4 -0
- data/spec/sandbox/config/simpler.yml +1 -0
- data/spec/sandbox/config/simpler_site.yml +2 -0
- data/spec/sandbox/config.yml +2 -0
- data/spec/sandbox/fixtures/examples.yml +8 -0
- data/spec/sandbox/fixtures/users.yml +2 -0
- data/spec/sandbox/flows/batman.rb +5 -0
- data/spec/sandbox/flows/robin.rb +4 -0
- data/spec/sandbox/pages/foo/bar_page.rb +9 -0
- data/spec/sandbox/pages/foo/partials/partial_the_reckoning.rb +2 -0
- data/spec/settings_spec.rb +103 -0
- data/spec/site_generator_spec.rb +62 -0
- data/spec/site_spec.rb +249 -0
- data/spec/spec_generator_helper.rb +40 -0
- data/spec/spec_generator_spec.rb +24 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/steps_generator_spec.rb +29 -0
- data/spec/string_spec.rb +17 -0
- data/spec/table_spec.rb +32 -0
- data/spec/taza_spec.rb +12 -0
- data/spec/watircraft_bin_spec.rb +14 -0
- data/watircraft.gemspec +53 -0
- data/watircraft_generators/page/USAGE +11 -0
- data/watircraft_generators/page/page_generator.rb +65 -0
- data/watircraft_generators/page/templates/page.rb.erb +8 -0
- data/watircraft_generators/site/site_generator.rb +51 -0
- data/watircraft_generators/site/templates/environments.yml.erb +4 -0
- data/watircraft_generators/site/templates/site.rb.erb +10 -0
- data/watircraft_generators/spec/USAGE +8 -0
- data/watircraft_generators/spec/spec_generator.rb +54 -0
- data/watircraft_generators/spec/templates/spec.rb.erb +17 -0
- data/watircraft_generators/steps/USAGE +13 -0
- data/watircraft_generators/steps/steps_generator.rb +62 -0
- data/watircraft_generators/steps/templates/steps.rb.erb +12 -0
- metadata +229 -0
data/lib/taza/site.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activesupport'
|
3
|
+
require 'taza/settings'
|
4
|
+
|
5
|
+
module Taza
|
6
|
+
# An abstraction of a website, but more really a container for a sites pages.
|
7
|
+
#
|
8
|
+
# You can generate a site by performing the following command:
|
9
|
+
# $ ./script/generate site google
|
10
|
+
#
|
11
|
+
# This will generate a site file for google, a flows folder, and a pages folder in lib
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# require 'taza'
|
16
|
+
#
|
17
|
+
# class Google < Taza::Site
|
18
|
+
#
|
19
|
+
# end
|
20
|
+
class Site
|
21
|
+
|
22
|
+
# These methods are available for user contexts, including Site itself
|
23
|
+
module Methods
|
24
|
+
attr_accessor :browser, :site
|
25
|
+
|
26
|
+
# Return an instance of the specified page. The name
|
27
|
+
# Given should be the human-form of the page, without the
|
28
|
+
# "page" suffix.
|
29
|
+
# If a block is given, it yields to the page.
|
30
|
+
def page(page_name, &block)
|
31
|
+
method_name = page_name.computerize + '_page'
|
32
|
+
send method_name, &block
|
33
|
+
end
|
34
|
+
|
35
|
+
# Send the browser to a url, relative to the site origin.
|
36
|
+
def goto relative_url
|
37
|
+
destination = File.join(@site.origin, relative_url)
|
38
|
+
@browser.goto destination
|
39
|
+
end
|
40
|
+
|
41
|
+
def pages
|
42
|
+
@pages || @site.pages
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
@@before_browser_closes = Proc.new() {}
|
48
|
+
# Use this to do something with the browser before it closes, but note that it is a class method which
|
49
|
+
# means that this will get called for any instance of a site.
|
50
|
+
#
|
51
|
+
# Here's an example of how you might use it to print the DOM output of a browser before it closes:
|
52
|
+
#
|
53
|
+
# Taza::Site.before_browser_closes do |browser|
|
54
|
+
# puts browser.html
|
55
|
+
# end
|
56
|
+
def self.before_browser_closes(&block)
|
57
|
+
@@before_browser_closes = block
|
58
|
+
end
|
59
|
+
|
60
|
+
# Site
|
61
|
+
attr_accessor :methods_module
|
62
|
+
|
63
|
+
# A site can be called a few different ways
|
64
|
+
#
|
65
|
+
# The following example creates a new browser object and closes it:
|
66
|
+
# Google.new do
|
67
|
+
# google.search.set "taza"
|
68
|
+
# google.submit.click
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# This example will create a browser object but not close it:
|
72
|
+
# Google.new.search.set "taza"
|
73
|
+
#
|
74
|
+
# Sites can take a couple of parameters in the constructor:
|
75
|
+
# :browser => a browser object to act on instead of creating one automatically
|
76
|
+
# (not sure if this is a useful feature or not)
|
77
|
+
def initialize(params={}, &block)
|
78
|
+
@site = self
|
79
|
+
@module_name = self.class.parent.to_s
|
80
|
+
@class_name = self.class.to_s.split("::").last
|
81
|
+
|
82
|
+
define_flows
|
83
|
+
|
84
|
+
if params[:browser]
|
85
|
+
@browser = params[:browser]
|
86
|
+
else
|
87
|
+
@browser = Browser.create(config)
|
88
|
+
@i_created_browser = true
|
89
|
+
end
|
90
|
+
|
91
|
+
page_loader = PageLoader.new(@module_name, pages_path)
|
92
|
+
@pages = page_loader.page_names
|
93
|
+
@methods_module = page_loader.page_methods
|
94
|
+
@methods_module.send(:include, Methods)
|
95
|
+
self.extend(@methods_module)
|
96
|
+
|
97
|
+
@browser.goto origin
|
98
|
+
|
99
|
+
execute_block_and_close_browser(&block) if block_given?
|
100
|
+
end
|
101
|
+
|
102
|
+
def config
|
103
|
+
Settings.config(@class_name)
|
104
|
+
end
|
105
|
+
|
106
|
+
# The base url of the site. This is configured in environments.yml.
|
107
|
+
def origin
|
108
|
+
config[:url]
|
109
|
+
end
|
110
|
+
|
111
|
+
def execute_block_and_close_browser
|
112
|
+
begin
|
113
|
+
yield self
|
114
|
+
rescue => site_block_exception
|
115
|
+
ensure
|
116
|
+
begin
|
117
|
+
close
|
118
|
+
rescue => close_exception
|
119
|
+
""
|
120
|
+
end
|
121
|
+
exception = site_block_exception || close_exception
|
122
|
+
raise exception if exception
|
123
|
+
end
|
124
|
+
end
|
125
|
+
private :execute_block_and_close_browser
|
126
|
+
|
127
|
+
def close
|
128
|
+
begin
|
129
|
+
@@before_browser_closes.call(@browser)
|
130
|
+
rescue => before_browser_closes_block_exception
|
131
|
+
"" # so basically rcov has a bug where it would insist this block is uncovered when empty
|
132
|
+
end
|
133
|
+
begin
|
134
|
+
@browser.close if @i_created_browser
|
135
|
+
ensure
|
136
|
+
raise before_browser_closes_block_exception if before_browser_closes_block_exception
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Return a context that supports the "watircraft" commands.
|
141
|
+
# Currently used by the script\console
|
142
|
+
def execution_context
|
143
|
+
initialize_context!(Object.new)
|
144
|
+
end
|
145
|
+
|
146
|
+
def initialize_context!(context)
|
147
|
+
context.extend @methods_module
|
148
|
+
context.site = @site
|
149
|
+
context.browser = @site.browser
|
150
|
+
context
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
def pages_path # :nodoc:
|
155
|
+
File.join(path,'pages','**','*.rb') # does this need to include partials?
|
156
|
+
end
|
157
|
+
|
158
|
+
def define_flows # :nodoc:
|
159
|
+
Dir.glob(flows_path) do |file|
|
160
|
+
require file
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# This is used to call a flow belonging to the site
|
165
|
+
#
|
166
|
+
# Example:
|
167
|
+
# Google.new do |google|
|
168
|
+
# google.flow(:perform_search, :query => "taza")
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# Where the flow would be defined under lib/sites/google/flows/perform_search.rb and look like:
|
172
|
+
# class PerformSearch < Taza::Flow
|
173
|
+
# alias :google :site
|
174
|
+
#
|
175
|
+
# def run(params={})
|
176
|
+
# google.search.set params[:query]
|
177
|
+
# google.submit.click
|
178
|
+
# end
|
179
|
+
# end
|
180
|
+
|
181
|
+
#
|
182
|
+
# methods that neither depend on or modify state
|
183
|
+
#
|
184
|
+
|
185
|
+
private
|
186
|
+
def flows_path # :nodoc:
|
187
|
+
File.join(path,'flows','*.rb')
|
188
|
+
end
|
189
|
+
|
190
|
+
def path # :nodoc:
|
191
|
+
File.join(base_path,'lib')
|
192
|
+
end
|
193
|
+
|
194
|
+
def base_path # :nodoc:
|
195
|
+
APP_ROOT
|
196
|
+
end
|
197
|
+
|
198
|
+
class PageLoader
|
199
|
+
attr_reader :page_methods, :page_names
|
200
|
+
def initialize site_module, pages_path
|
201
|
+
@site_module = site_module
|
202
|
+
@pages_path = pages_path
|
203
|
+
@page_methods = Module.new
|
204
|
+
@page_names = []
|
205
|
+
define_site_pages
|
206
|
+
end
|
207
|
+
private
|
208
|
+
def define_site_pages # :nodoc:
|
209
|
+
Dir.glob(@pages_path) do |file|
|
210
|
+
require file
|
211
|
+
page_name = File.basename(file,'.rb')
|
212
|
+
@page_names << page_name
|
213
|
+
page_class = "#{@site_module}::#{page_name.camelize}"
|
214
|
+
@page_methods.module_eval <<-EOS
|
215
|
+
def #{page_name}
|
216
|
+
page = #{page_class}.new
|
217
|
+
page.browser = @browser
|
218
|
+
page.site = @site
|
219
|
+
yield page if block_given?
|
220
|
+
page
|
221
|
+
end
|
222
|
+
EOS
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
data/lib/taza/tasks.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'taglob/rake/tasks'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
def tags
|
8
|
+
ENV['TAGS']
|
9
|
+
end
|
10
|
+
|
11
|
+
def format_options(file_name)
|
12
|
+
file_name = "artifacts/#{file_name}/index.html"
|
13
|
+
dir_name = File.dirname(file_name)
|
14
|
+
FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
|
15
|
+
["--format","html:#{file_name}","--format","p"]
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run all functional specs"
|
19
|
+
Spec::Rake::SpecTask.new :spec do |t|
|
20
|
+
t.spec_files = Dir.taglob('test/specs/**/*_spec.rb',tags)
|
21
|
+
t.spec_opts << format_options("functional/all")
|
22
|
+
end
|
23
|
+
task :specs => :spec
|
24
|
+
|
25
|
+
require 'cucumber/rake/task'
|
26
|
+
Cucumber::Rake::Task.new do |t|
|
27
|
+
t.cucumber_opts = '--format pretty'
|
28
|
+
t.step_pattern = "lib/steps/**/*.rb"
|
29
|
+
t.feature_pattern = "test/features/**/*.feature"
|
30
|
+
end
|
data/lib/taza.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'taza/page'
|
2
|
+
require 'taza/site'
|
3
|
+
require 'taza/browser'
|
4
|
+
require 'taza/settings'
|
5
|
+
require 'taza/flow'
|
6
|
+
require 'taza/entity'
|
7
|
+
require 'taza/fixture'
|
8
|
+
require 'extensions/object'
|
9
|
+
require 'extensions/string'
|
10
|
+
require 'extensions/hash'
|
11
|
+
require 'extensions/array'
|
12
|
+
|
13
|
+
module Taza
|
14
|
+
VERSION = '0.8.1'
|
15
|
+
|
16
|
+
def self.windows?
|
17
|
+
PLATFORM.include?("mswin")
|
18
|
+
end
|
19
|
+
def self.osx?
|
20
|
+
PLATFORM.include?("darwin")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ForwardInitialization
|
25
|
+
module ClassMethods
|
26
|
+
def new(*args,&block)
|
27
|
+
const_get("#{name.split("::").last}").new(*args,&block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.included(klass)
|
32
|
+
klass.extend(ClassMethods)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'taza/settings'
|
2
|
+
|
3
|
+
module WatirCraft
|
4
|
+
# Assumes #site_name and #destination_root and #usage methods are defined.
|
5
|
+
module GeneratorHelper
|
6
|
+
protected
|
7
|
+
def configured_validated_site
|
8
|
+
site = configured_site
|
9
|
+
check_if_site_exists site
|
10
|
+
site
|
11
|
+
end
|
12
|
+
def configured_site
|
13
|
+
site_name = Taza::Settings.config_file[:site]
|
14
|
+
end
|
15
|
+
def check_if_site_exists site_name=@site_name
|
16
|
+
if site_name.nil?
|
17
|
+
raise RubiGen::UsageError,
|
18
|
+
"Error. A site must first be specified in config.yml"
|
19
|
+
end
|
20
|
+
site_file = File.join(destination_root,'lib',"#{site_name.underscore}.rb")
|
21
|
+
unless File.exists?(site_file)
|
22
|
+
raise RubiGen::UsageError,
|
23
|
+
"Error. Site file #{site_file} not found. (Check config.yml)"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module WatirCraft
|
2
|
+
class Table
|
3
|
+
class << self
|
4
|
+
def row_class
|
5
|
+
@row_class ||= Class.new(Row)
|
6
|
+
end
|
7
|
+
def field(name, &block)
|
8
|
+
row_class.field(name, &block)
|
9
|
+
end
|
10
|
+
def element(name, &block)
|
11
|
+
row_class.element(name, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def initialize watir_table, &block
|
15
|
+
@watir_table = watir_table
|
16
|
+
end
|
17
|
+
def row selector
|
18
|
+
@watir_table.rows.each do | row |
|
19
|
+
wrapped = self.class.row_class.new row
|
20
|
+
# note: we are only looking at the first key/value
|
21
|
+
method = selector.keys[0]
|
22
|
+
value = selector[method]
|
23
|
+
return wrapped if wrapped.send(method) == value
|
24
|
+
end
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Row
|
30
|
+
class << self
|
31
|
+
def element name, &block
|
32
|
+
define_method(name) do
|
33
|
+
instance_eval &block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def field name, &block
|
37
|
+
element_name = "#{name}_element"
|
38
|
+
element element_name, &block
|
39
|
+
define_method(name) do
|
40
|
+
send(element_name).display_value
|
41
|
+
end
|
42
|
+
define_method("#{name}=") do | value |
|
43
|
+
send(element_name).set value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def initialize watir_row
|
48
|
+
@row = watir_row
|
49
|
+
end
|
50
|
+
# Returns true. If the row doesn't exist, you'll get nil as the return
|
51
|
+
# value of Table#row.
|
52
|
+
def exist?
|
53
|
+
true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/watircraft.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'watircraft/version'
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe 'Array Extensions' do
|
4
|
+
it "should know if elements are not equivilent to a subset of those elements" do
|
5
|
+
[1,2,3].should_not be_equivalent([2,3])
|
6
|
+
end
|
7
|
+
it "should know if elements are not equivilent to a larger set including those elements" do
|
8
|
+
[1,2,3].should_not be_equivalent([1,2,3,4])
|
9
|
+
end
|
10
|
+
it "should know it is equivalent if the same order" do
|
11
|
+
[1,2,3].should be_equivalent([1,2,3])
|
12
|
+
end
|
13
|
+
it "should know it is equivalent if the different orders" do
|
14
|
+
[1,2,3].should be_equivalent([2,1,3])
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza/browser'
|
3
|
+
require 'taza/settings'
|
4
|
+
require 'selenium'
|
5
|
+
require 'watir'
|
6
|
+
|
7
|
+
describe Taza::Browser do
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
reset_env_vars
|
11
|
+
Taza::Settings.stubs(:config_file).returns({})
|
12
|
+
ENV['ENVIRONMENT'] = 'test'
|
13
|
+
end
|
14
|
+
|
15
|
+
after :all do
|
16
|
+
reset_env_vars
|
17
|
+
end
|
18
|
+
def reset_env_vars
|
19
|
+
ENV['ENVIRONMENT'] = nil
|
20
|
+
ENV['SERVER_PORT'] = nil
|
21
|
+
ENV['SERVER_IP'] = nil
|
22
|
+
ENV['BROWSER'] = nil
|
23
|
+
ENV['DRIVER'] = nil
|
24
|
+
ENV['TIMEOUT'] = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise unknown browser error for unsupported watir browsers" do
|
28
|
+
lambda { Taza::Browser.create(:browser => :foo_browser_9000,:driver => :watir) }.should raise_error(StandardError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should use params browser type when creating selenium" do
|
32
|
+
browser_type = :opera
|
33
|
+
Selenium::SeleniumDriver.expects(:new).with(anything,anything,'*opera',anything)
|
34
|
+
Taza::Browser.create(:browser => browser_type, :driver => :selenium)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise selenium unsupported browser error" do
|
38
|
+
Taza::Browser.create(:browser => :foo, :driver => :selenium)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to create a selenium instance" do
|
42
|
+
browser = Taza::Browser.create(:browser => :firefox, :driver => :selenium)
|
43
|
+
browser.should be_a_kind_of(Selenium::SeleniumDriver)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should use environment settings for server port and ip" do
|
47
|
+
Taza::Settings.stubs(:path).returns(File.join('spec','sandbox'))
|
48
|
+
ENV['SERVER_PORT'] = 'server_port'
|
49
|
+
ENV['SERVER_IP'] = 'server_ip'
|
50
|
+
ENV['DRIVER'] = 'selenium'
|
51
|
+
Selenium::SeleniumDriver.expects(:new).with('server_ip','server_port',anything,anything)
|
52
|
+
Taza::Browser.create(Taza::Settings.config("SiteName"))
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should use environment settings for timeout" do
|
56
|
+
Taza::Settings.stubs(:path).returns(File.join('spec','sandbox'))
|
57
|
+
ENV['TIMEOUT'] = 'timeout'
|
58
|
+
ENV['DRIVER'] = 'selenium'
|
59
|
+
Selenium::SeleniumDriver.expects(:new).with(anything,anything,anything,'timeout')
|
60
|
+
Taza::Browser.create(Taza::Settings.config("SiteName"))
|
61
|
+
end
|
62
|
+
|
63
|
+
# a test of a stub for testing the test harness of our tests
|
64
|
+
it "should provide a fake browser, so we can test our test harness" do
|
65
|
+
Taza::Browser.create(:driver => :fake).should be_a(Taza::FakeBrowser)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/spec/entity_spec.rb
ADDED
data/spec/fake_table.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
# Replaces watir table in WatirCraft unit tests
|
4
|
+
class FakeTable
|
5
|
+
attr_accessor :rows
|
6
|
+
def initialize structure
|
7
|
+
@rows = structure.map {|hash| FakeRow.new(hash)}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class FakeRow
|
12
|
+
def initialize hash
|
13
|
+
@hash = hash
|
14
|
+
end
|
15
|
+
def element name
|
16
|
+
FakeElement.new @hash, name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class FakeElement
|
21
|
+
def initialize hash, name
|
22
|
+
@hash = hash
|
23
|
+
@name = name
|
24
|
+
end
|
25
|
+
def display_value
|
26
|
+
@hash[@name]
|
27
|
+
end
|
28
|
+
def exist?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
def set value
|
32
|
+
@hash[@name] = value
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza'
|
3
|
+
|
4
|
+
describe Taza::Fixture do
|
5
|
+
|
6
|
+
it "should be able to load entries from fixtures" do
|
7
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
8
|
+
fixture = Taza::Fixture.new
|
9
|
+
fixture.load_all
|
10
|
+
example = fixture.get_fixture_entity(:examples,'first_example')
|
11
|
+
example.name.should eql("first")
|
12
|
+
example.price.should eql(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should use the spec folder as the base path" do
|
16
|
+
Taza::Fixture.new.base_path.should eql('./spec')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should know if a pluralized fixture of that name exists" do
|
20
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
21
|
+
fixture = Taza::Fixture.new
|
22
|
+
fixture.load_all
|
23
|
+
fixture.pluralized_fixture_exists?('example').should be_true
|
24
|
+
fixture.pluralized_fixture_exists?('foo').should be_false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to get all fixtures loaded" do
|
28
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
29
|
+
fixture = Taza::Fixture.new
|
30
|
+
fixture.load_all
|
31
|
+
fixture.fixture_names.should be_equivalent([:examples,:users])
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'taza/fixture'
|
3
|
+
|
4
|
+
describe Taza::Fixtures do
|
5
|
+
Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
|
6
|
+
include Taza::Fixtures
|
7
|
+
|
8
|
+
it "should be able to look up a fixture entity off fixture_methods module" do
|
9
|
+
examples(:first_example).name.should eql('first')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should still raise method missing error" do
|
13
|
+
lambda{zomgwtf(:first_example)}.should raise_error(NoMethodError)
|
14
|
+
end
|
15
|
+
|
16
|
+
#TODO: this test tests what is in entity's instance eval not happy with it being here
|
17
|
+
it "should be able to look up a fixture entity off fixture_methods module" do
|
18
|
+
examples(:first_example).user.name.should eql(users(:shatner).name)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/hash_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe 'Hash Extensions' do
|
4
|
+
it "should add methods for hash keys to some instance" do
|
5
|
+
entity = {'apple' => 'pie'}.convert_hash_keys_to_methods(nil)
|
6
|
+
entity.should respond_to(:apple)
|
7
|
+
end
|
8
|
+
it "should not add the methods to a hash" do
|
9
|
+
entity = {'apple' => 'pie'}.convert_hash_keys_to_methods(nil)
|
10
|
+
entity.should_not be_a_instance_of(Hash)
|
11
|
+
end
|
12
|
+
end
|
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "Object" do
|
4
|
+
before :all do
|
5
|
+
@orig_version = VERSION
|
6
|
+
Object.send :remove_const, :VERSION
|
7
|
+
Object.const_set :VERSION, "1.8.6"
|
8
|
+
load 'lib/extensions/object.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
after :all do
|
12
|
+
Object.send :remove_const, :VERSION
|
13
|
+
Object.const_set :VERSION, @orig_version
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should execute blocks with args in instance context" do
|
17
|
+
str = "string"
|
18
|
+
|
19
|
+
class << str
|
20
|
+
def my_singleton_method(arg)
|
21
|
+
arg
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
block = Proc.new { |arg| my_singleton_method(arg) }
|
26
|
+
|
27
|
+
str.instance_exec("foo",&block).should == "foo"
|
28
|
+
end
|
29
|
+
end
|