test-harness 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/configuration.rb +6 -0
- data/lib/given.rb +13 -0
- data/lib/mental_model.rb +5 -0
- data/lib/test_harness.rb +41 -0
- data/lib/test_helper.rb +9 -0
- data/lib/ui_component.rb +11 -0
- data/lib/ui_component_helper.rb +77 -0
- data/lib/ui_driver.rb +7 -0
- data/lib/ui_helper.rb +13 -0
- data/lib/ui_view.rb +7 -0
- data/test-harness.gemspec +10 -1
- metadata +12 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/given.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestHarness
|
3
|
+
class Given
|
4
|
+
include TestHarness::TestHelper
|
5
|
+
|
6
|
+
Dir.glob(File.expand_path('../given/*.rb', __FILE__)).each do |file|
|
7
|
+
klass = ("TestHarness::Given::%s" % File.basename(file, '.rb').camelize).constantize
|
8
|
+
include klass
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
data/lib/mental_model.rb
ADDED
data/lib/test_harness.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'given'
|
2
|
+
require 'ui_component'
|
3
|
+
|
4
|
+
class TestHarness
|
5
|
+
class << self
|
6
|
+
def configuration
|
7
|
+
@configuation ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def configure(&block)
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def given
|
15
|
+
@given ||= TestHarness::Given.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def uiv
|
19
|
+
@uiv ||= TestHarness::UIView.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def uid
|
23
|
+
@uid ||= TestHarness::UIDriver.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def mm
|
27
|
+
@mm ||= TestHarness::MentalModel.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def register_instance_option(scope, option_name, default_value = nil)
|
31
|
+
scope.send(:define_method, option_name) do |*args, &block|
|
32
|
+
if !args[0].nil? || block
|
33
|
+
instance_variable_set("@#{option_name}_registered", args[0].nil? ? block : args[0])
|
34
|
+
else
|
35
|
+
instance_variable_get("@#{option_name}_registered") || default_value || yield
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/lib/test_helper.rb
ADDED
data/lib/ui_component.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
class TestHarness
|
2
|
+
module UIComponentHelper
|
3
|
+
def component
|
4
|
+
self.class.parent.component
|
5
|
+
end
|
6
|
+
|
7
|
+
# If the UIComponent is sent a message it does not understand, it will
|
8
|
+
# forward that message on to its {#browser} but wrap the call in a block
|
9
|
+
# provided to the the browser's `#within` method. This provides convenient
|
10
|
+
# access to the browser driver's DSL, automatically scoped to this
|
11
|
+
# component.
|
12
|
+
def method_missing(name, *args, &block)
|
13
|
+
if respond_to?(name)
|
14
|
+
browser.within(component.within) do
|
15
|
+
browser.send(name, *args, &block)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Since Kernel#select is defined, we have to override it specifically here.
|
23
|
+
def select(*args, &block)
|
24
|
+
browser.within(component.within) do
|
25
|
+
browser.select(*args, &block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# We don't want to go through the method_missing above for visit, but go
|
30
|
+
# directly to the browser object
|
31
|
+
def visit(path)
|
32
|
+
path = "%s:%s%s" % [server_host, Capybara.server_port, path] if path !~ /^http/
|
33
|
+
|
34
|
+
browser.visit(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def show!
|
38
|
+
visit component_path
|
39
|
+
end
|
40
|
+
|
41
|
+
def component_path
|
42
|
+
component.path.gsub(/:\w+/) {|match| mm.subject.send(match.tr(':',''))}
|
43
|
+
end
|
44
|
+
|
45
|
+
def submit!
|
46
|
+
form_hash.each do |k,v|
|
47
|
+
fill_in k.to_s, :with => v
|
48
|
+
end
|
49
|
+
|
50
|
+
if has_css?(locator = component.submit)
|
51
|
+
find(:css, component.submit).click
|
52
|
+
else
|
53
|
+
click_on component.submit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def form_hash
|
58
|
+
form.instance_variable_get("@table")
|
59
|
+
end
|
60
|
+
|
61
|
+
def form
|
62
|
+
@form ||= OpenStruct.new
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
# @private
|
67
|
+
# (Not really private, but YARD seemingly lacks RDoc's :nodoc tag, and the
|
68
|
+
# semantics here don't differ from Object#respond_to?)
|
69
|
+
def respond_to?(name)
|
70
|
+
super || browser.respond_to?(name)
|
71
|
+
end
|
72
|
+
|
73
|
+
def server_host
|
74
|
+
configuration.server_host || Capybara.default_host || 'http://example.com'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/ui_driver.rb
ADDED
data/lib/ui_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class TestHarness
|
2
|
+
class UIHelper
|
3
|
+
def self.register_ui_components
|
4
|
+
Dir.glob(File.expand_path('../ui/*.rb', __FILE__)).each do |file|
|
5
|
+
component = File.basename(file, '.rb')
|
6
|
+
klass = ("TestHarness::%s::%s" % [component.camelize, self.name.split('::').last]).constantize
|
7
|
+
TestHarness.register_instance_option(self, component, klass.new)
|
8
|
+
klass.send(:include, TestHarness::UIComponentHelper)
|
9
|
+
klass.send(:include, TestHarness::TestHelper)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/ui_view.rb
ADDED
data/test-harness.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "test-harness"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Maher Hawash"]
|
@@ -25,7 +25,16 @@ Gem::Specification.new do |s|
|
|
25
25
|
"README.rdoc",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
|
+
"lib/configuration.rb",
|
29
|
+
"lib/given.rb",
|
30
|
+
"lib/mental_model.rb",
|
28
31
|
"lib/test_harness.rb",
|
32
|
+
"lib/test_helper.rb",
|
33
|
+
"lib/ui_component.rb",
|
34
|
+
"lib/ui_component_helper.rb",
|
35
|
+
"lib/ui_driver.rb",
|
36
|
+
"lib/ui_helper.rb",
|
37
|
+
"lib/ui_view.rb",
|
29
38
|
"spec/spec_helper.rb",
|
30
39
|
"spec/test_harness_spec.rb",
|
31
40
|
"test-harness.gemspec"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-harness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Maher Hawash
|
@@ -91,7 +91,16 @@ files:
|
|
91
91
|
- README.rdoc
|
92
92
|
- Rakefile
|
93
93
|
- VERSION
|
94
|
+
- lib/configuration.rb
|
95
|
+
- lib/given.rb
|
96
|
+
- lib/mental_model.rb
|
94
97
|
- lib/test_harness.rb
|
98
|
+
- lib/test_helper.rb
|
99
|
+
- lib/ui_component.rb
|
100
|
+
- lib/ui_component_helper.rb
|
101
|
+
- lib/ui_driver.rb
|
102
|
+
- lib/ui_helper.rb
|
103
|
+
- lib/ui_view.rb
|
95
104
|
- spec/spec_helper.rb
|
96
105
|
- spec/test_harness_spec.rb
|
97
106
|
- test-harness.gemspec
|