gizmo 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/{README.md → README.markdown} +12 -25
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/bin/gizmo +3 -40
- data/features/github_example.feature +12 -0
- data/features/step_definitions/{gizmo_steps.rb → github_example_steps.rb} +7 -7
- data/features/support/env.rb +1 -1
- data/features/support/pages/page_with_github_repo_details.rb +3 -3
- data/features/support/pages/page_with_github_search.rb +2 -2
- data/features/support/pages/page_with_github_search_results.rb +13 -13
- data/features/support/patches/capybara.rb +0 -39
- data/gizmo.gemspec +9 -6
- data/lib/gizmo.rb +1 -1
- data/lib/gizmo/extras.rb +7 -5
- data/lib/gizmo/helpers.rb +18 -10
- data/lib/gizmo/page.rb +12 -0
- data/spec/github_site_example_spec.rb +0 -4
- data/spec/gizmo/extras_spec.rb +5 -9
- data/spec/gizmo/helpers_spec.rb +2 -7
- data/spec/gizmo/page_spec.rb +22 -0
- data/spec/spec_helper.rb +2 -2
- metadata +25 -11
- data/features/gizmo.feature +0 -12
data/.gitignore
CHANGED
@@ -2,47 +2,34 @@ Gizmo
|
|
2
2
|
============
|
3
3
|
|
4
4
|
In homage to its humble beginnings as our 'gremlin' testing submodule.<br />
|
5
|
-
|
5
|
+
With which we were entrusted and asked to follow 3 simple rules...
|
6
6
|
|
7
7
|
* "Don't get it wet"
|
8
8
|
* "Keep it away from bright lights....especially sunlight"
|
9
9
|
* "Don't ever feed it after midnight"
|
10
10
|
|
11
11
|
We didn't listen, and it got nasty...<br />
|
12
|
-
So we've gone back to the drawing board and come up with a friendlier, cuddlier testing helper.
|
12
|
+
So, we've gone back to the drawing board and come up with a friendlier, cuddlier testing helper.
|
13
13
|
|
14
14
|
**Gizmo** is a simple page model testing framework used and sponsored by [realestate.com.au](http://www.realestate.com.au). The aim of the project is to DRY up testing assertions by abstracting code that defines your page, resulting in a consistent, easy to maintain test suite. The code is maintained by Contributors from REA, and largely based on concepts brought to REA by [Mark Ryall](http://github.com/markryall) and other [thoughtworkers](http://thoughtworks.com.au/)
|
15
15
|
|
16
|
-
**this project is a work in progress, and not really ready to be used for its intended purpose!**
|
17
16
|
|
17
|
+
Usage
|
18
|
+
------------
|
19
|
+
* [with Cucumber](http://wiki.github.com/icaruswings/gizmo/cucumber)
|
20
|
+
* [with RSpec](http://wiki.github.com/icaruswings/gizmo/rspec)
|
18
21
|
|
19
|
-
## Usage ##
|
20
|
-
|
21
|
-
see [this gist](http://gist.github.com/339570) for some code examples
|
22
|
-
|
23
|
-
**for cucumber:**
|
24
|
-
|
25
|
-
* write your features just like you usually would
|
26
|
-
* require 'gizmo' and add the Gizmo::Helpers to the World
|
27
|
-
* generate your page mixins and fill them out with your page selectors
|
28
|
-
* use the page model when writing your steps
|
29
|
-
|
30
|
-
|
31
|
-
**for rspec:**
|
32
|
-
|
33
|
-
* require 'gizmo' in your spec_helper and include Gizmo::Helpers methods
|
34
|
-
* generate your page mixins and fill them out with your page selectors
|
35
|
-
* use the page model when writing your specs
|
36
|
-
|
37
|
-
|
38
|
-
## Contributing ##
|
39
22
|
|
23
|
+
Contributing
|
24
|
+
------------
|
40
25
|
* Fork the project.
|
41
26
|
* Make your feature addition or bug fix.
|
42
27
|
* Make sure you write tests. Pull requests will not be accepted unless they have complete coverage.
|
43
|
-
* Commit, do not mess with
|
28
|
+
* Commit, do not mess with Rakefile, VERSION, or history.
|
44
29
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
45
30
|
* Send me a pull request.
|
46
31
|
|
47
|
-
|
32
|
+
|
33
|
+
Sponsored by
|
34
|
+
------------
|
48
35
|
[realestate.com.au](http://www.realestate.com.au)
|
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ begin
|
|
14
14
|
gem.add_development_dependency "cucumber", ">= 0.6.3"
|
15
15
|
gem.add_development_dependency "webrat", ">= 0.7.0"
|
16
16
|
gem.add_development_dependency "capybara", ">= 0.3.5"
|
17
|
+
gem.add_development_dependency "metric_fu", ">= 1.3.0"
|
17
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
19
|
gem.add_dependency "nokogiri", ">= 1.4.1"
|
19
20
|
gem.add_dependency "activesupport", ">= 2.3.5"
|
@@ -23,6 +24,8 @@ rescue LoadError
|
|
23
24
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
25
|
end
|
25
26
|
|
27
|
+
require 'metric_fu'
|
28
|
+
|
26
29
|
require 'spec/rake/spectask'
|
27
30
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
28
31
|
spec.libs << 'lib' << 'spec'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/bin/gizmo
CHANGED
@@ -7,46 +7,11 @@ require 'active_support'
|
|
7
7
|
$LOAD_PATH << File.dirname(__FILE__) + '/../lib'
|
8
8
|
require 'gizmo'
|
9
9
|
|
10
|
-
@current_mixin = nil
|
11
|
-
|
12
|
-
def puts_list methods
|
13
|
-
return puts "[]" if methods.empty?
|
14
|
-
puts methods.sort.join(', ')
|
15
|
-
end
|
16
10
|
|
17
11
|
opts = OptionParser.new do |opts|
|
18
12
|
|
19
|
-
opts.on("-v", "--version"
|
20
|
-
puts "gizmo
|
21
|
-
end
|
22
|
-
|
23
|
-
opts.on("-g", "--generate-mixin [NAME]", "generate a new page mixin") do |mixin_name|
|
24
|
-
File.open("#{Gizmo::Config.mixin_path}/page_with_#{mixin_name}.rb", "w") do |file|
|
25
|
-
content = <<-EOS
|
26
|
-
module PageWith#{mixin_name.camelize}
|
27
|
-
# def valid
|
28
|
-
# has_selector?('my-container')
|
29
|
-
# end
|
30
|
-
end
|
31
|
-
EOS
|
32
|
-
file.write(content.strip)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
opts.on("-p", "--with-page [NAME]") do |mixin_name|
|
37
|
-
Gizmo.load_mixins! File.join(Dir.pwd, Gizmo::Config.mixin_path)
|
38
|
-
mixin = Object.const_get("PageWith" + mixin_name.camelize)
|
39
|
-
@current_mixin = { :name => mixin_name, :obj => Gizmo::Page.new({}, '', {}).extend(mixin) }
|
40
|
-
end
|
41
|
-
|
42
|
-
opts.on('-m', '--list-methods', 'list all the methods for a mixin') do
|
43
|
-
puts "---- methods for #{@current_mixin[:name]} ----"
|
44
|
-
puts_list @current_mixin[:obj].methods
|
45
|
-
end
|
46
|
-
|
47
|
-
opts.on('-f', '--filter-methods [QUERY]', 'filter methods for a mixin') do |query|
|
48
|
-
puts "---- methods for #{@current_mixin[:name]} matching #{query} ----"
|
49
|
-
puts_list @current_mixin[:obj].methods.select { |m| m =~ /#{query}/ }
|
13
|
+
opts.on("-v", "--version") do
|
14
|
+
puts "gizmo #{IO.readlines(File.join(File.dirname(__FILE__), '..', 'VERSION'))}"
|
50
15
|
end
|
51
16
|
|
52
17
|
end
|
@@ -57,6 +22,4 @@ if ARGV.size == 0
|
|
57
22
|
exit 1
|
58
23
|
end
|
59
24
|
|
60
|
-
opts.parse!
|
61
|
-
|
62
|
-
@current_mixin = nil
|
25
|
+
opts.parse!
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature:
|
2
|
+
As a behaviour driven developer
|
3
|
+
In order to have a DRY, elegant and maintainable test suite
|
4
|
+
I want 'gizmo' to do it's funky thing
|
5
|
+
|
6
|
+
Scenario: A user can perform a search from the homepage
|
7
|
+
Given a user is on the github homepage
|
8
|
+
When the user enters "gizmo" into the search box
|
9
|
+
And the user clicks the magnifying glass icon
|
10
|
+
And the user clicks on the "icaruswings / gizmo" link
|
11
|
+
Then the user is on the "gizmo" github repository details page
|
12
|
+
And the user is on a github repository details page which belongs to "icaruswings"
|
@@ -1,36 +1,36 @@
|
|
1
|
-
Given /^
|
1
|
+
Given /^a user is on the github homepage$/ do
|
2
2
|
visit "http://github.com"
|
3
3
|
end
|
4
4
|
|
5
|
-
When /^the
|
5
|
+
When /^the user enters "([^\"]*)" into the search box$/ do |text|
|
6
6
|
on_page_with :github_search do |page|
|
7
7
|
fill_in page.search_form.input.attr('name').value, :with => text
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
When /^the
|
11
|
+
When /^the user clicks the magnifying glass icon$/ do
|
12
12
|
on_page_with :github_search do |page|
|
13
13
|
click page.search_form.submit.attr('alt').value
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
When /^the
|
17
|
+
When /^the user clicks on the "([^\"]*)" link$/ do |text|
|
18
18
|
click_link text
|
19
19
|
end
|
20
20
|
|
21
|
-
Then /^the
|
21
|
+
Then /^the user is on a github repository details page$/ do
|
22
22
|
on_page_with :github_repo_details do |page|
|
23
23
|
page.should be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
Then /^the
|
27
|
+
Then /^the user is on the "([^\"]*)" github repository details page$/ do |repo_name|
|
28
28
|
on_page_with :github_repo_details do |page|
|
29
29
|
page.repo_details.name == repo_name
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
Then /^the
|
33
|
+
Then /^the user is on a github repository details page which belongs to "([^\"]*)"$/ do |author|
|
34
34
|
on_page_with :github_repo_details do |page|
|
35
35
|
page.repo_details.author == author
|
36
36
|
end
|
data/features/support/env.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module PageWithGithubRepoDetails
|
2
|
-
|
2
|
+
|
3
3
|
def valid?
|
4
4
|
has_selector?("div.repohead")
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def repo_details
|
8
|
-
|
8
|
+
element_struct do |repo_details|
|
9
9
|
repo_details.name = @document.css("h1>strong a").inner_text
|
10
10
|
repo_details.author = @document.css("h1>a").inner_text
|
11
11
|
end
|
@@ -3,9 +3,9 @@ module PageWithGithubSearch
|
|
3
3
|
def valid?
|
4
4
|
has_selector?("div.search")
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def search_form
|
8
|
-
|
8
|
+
element_struct do |form|
|
9
9
|
form.container = @document.css("div.search")
|
10
10
|
form.element = container = form.container.css("form")
|
11
11
|
form.input = container.css("input[name=q]")
|
@@ -3,35 +3,35 @@ module PageWithGithubSearchResults
|
|
3
3
|
def valid?
|
4
4
|
has_selector?('div#code_search_results')
|
5
5
|
end
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
|
8
8
|
def search_results
|
9
|
-
|
9
|
+
element_struct do |results|
|
10
10
|
results.repositories = build_repositories
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
|
15
15
|
private
|
16
|
-
|
16
|
+
|
17
17
|
def build_repositories
|
18
|
-
|
18
|
+
element_struct do |repos|
|
19
19
|
container = find_results_container "Repositories"
|
20
20
|
repos.heading = container.css('div.header')
|
21
21
|
repos.results = container.css('div.result').map { |result| build_repository_result result }
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def build_repository_result result
|
26
|
-
|
26
|
+
element_struct do |repo_result|
|
27
27
|
repo_result.title = result.css('h2.title')
|
28
28
|
repo_result.link = repo_result.title.css('a')
|
29
|
-
link_parts = repo_result.link.inner_text.split('/')
|
30
|
-
repo_result.
|
31
|
-
repo_result.
|
29
|
+
link_parts = repo_result.link.inner_text.split('/').map(&:strip)
|
30
|
+
repo_result.author = link_parts[0]
|
31
|
+
repo_result.name = link_parts[1]
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def find_results_container heading_text
|
36
36
|
all_headings = @document.css('div.header')
|
37
37
|
header = all_headings.find do |heading_element|
|
@@ -1,44 +1,5 @@
|
|
1
1
|
if Object.const_defined? :Capybara
|
2
|
-
|
3
2
|
module Capybara
|
4
3
|
alias :response :page
|
5
4
|
end
|
6
|
-
|
7
|
-
class Capybara::Driver::Selenium < Capybara::Driver::Base
|
8
|
-
class Node < Capybara::Node
|
9
|
-
|
10
|
-
def is_radio?
|
11
|
-
tag_name == 'input' and type == 'radio'
|
12
|
-
end
|
13
|
-
|
14
|
-
def is_checkbox?
|
15
|
-
tag_name == 'input' and type == 'checkbox'
|
16
|
-
end
|
17
|
-
|
18
|
-
def is_text_field?
|
19
|
-
tag_name == 'textarea' or (tag_name == 'input' and %w(text password hidden file).include?(type))
|
20
|
-
end
|
21
|
-
|
22
|
-
def radio_input
|
23
|
-
node.select
|
24
|
-
end
|
25
|
-
|
26
|
-
def checkbox_input
|
27
|
-
node.click
|
28
|
-
end
|
29
|
-
|
30
|
-
def clear_and_send_keys value
|
31
|
-
node.clear
|
32
|
-
node.send_keys(value.to_s)
|
33
|
-
end
|
34
|
-
|
35
|
-
def set(value)
|
36
|
-
return clear_and_send_keys(value) if is_text_field?
|
37
|
-
return radio_input if is_radio?
|
38
|
-
return checkbox_input if is_checkbox?
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
5
|
end
|
data/gizmo.gemspec
CHANGED
@@ -5,29 +5,29 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gizmo}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Luke Cunningham", "Steven Holloway", "Sam Weller"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-10}
|
13
13
|
s.default_executable = %q{gizmo}
|
14
14
|
s.description = %q{gizmo is a simple page model testing framework used and sponsored by 'realestate.com.au'. The aim of the project is to DRY up your testing assertions by abstracting code that defines your page resulting in a consistent, easy to maintain test suit}
|
15
15
|
s.email = %q{luke@icaruswings.com}
|
16
16
|
s.executables = ["gizmo"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
19
|
-
"README.
|
19
|
+
"README.markdown"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".gitignore",
|
24
24
|
"LICENSE",
|
25
|
-
"README.
|
25
|
+
"README.markdown",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"bin/gizmo",
|
29
|
-
"features/
|
30
|
-
"features/step_definitions/
|
29
|
+
"features/github_example.feature",
|
30
|
+
"features/step_definitions/github_example_steps.rb",
|
31
31
|
"features/support/env.rb",
|
32
32
|
"features/support/pages/page_with_github_repo_details.rb",
|
33
33
|
"features/support/pages/page_with_github_search.rb",
|
@@ -72,6 +72,7 @@ Gem::Specification.new do |s|
|
|
72
72
|
s.add_development_dependency(%q<cucumber>, [">= 0.6.3"])
|
73
73
|
s.add_development_dependency(%q<webrat>, [">= 0.7.0"])
|
74
74
|
s.add_development_dependency(%q<capybara>, [">= 0.3.5"])
|
75
|
+
s.add_development_dependency(%q<metric_fu>, [">= 1.3.0"])
|
75
76
|
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.1"])
|
76
77
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
|
77
78
|
else
|
@@ -79,6 +80,7 @@ Gem::Specification.new do |s|
|
|
79
80
|
s.add_dependency(%q<cucumber>, [">= 0.6.3"])
|
80
81
|
s.add_dependency(%q<webrat>, [">= 0.7.0"])
|
81
82
|
s.add_dependency(%q<capybara>, [">= 0.3.5"])
|
83
|
+
s.add_dependency(%q<metric_fu>, [">= 1.3.0"])
|
82
84
|
s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
|
83
85
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
84
86
|
end
|
@@ -87,6 +89,7 @@ Gem::Specification.new do |s|
|
|
87
89
|
s.add_dependency(%q<cucumber>, [">= 0.6.3"])
|
88
90
|
s.add_dependency(%q<webrat>, [">= 0.7.0"])
|
89
91
|
s.add_dependency(%q<capybara>, [">= 0.3.5"])
|
92
|
+
s.add_dependency(%q<metric_fu>, [">= 1.3.0"])
|
90
93
|
s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
|
91
94
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
92
95
|
end
|
data/lib/gizmo.rb
CHANGED
@@ -8,7 +8,6 @@ module Gizmo
|
|
8
8
|
|
9
9
|
autoload :Page, "gizmo/page"
|
10
10
|
autoload :Helpers, "gizmo/helpers"
|
11
|
-
autoload :Generate, "gizmo/generate"
|
12
11
|
|
13
12
|
GizmoError = Class.new(StandardError)
|
14
13
|
MixinNotValidError = Class.new(GizmoError)
|
@@ -16,5 +15,6 @@ module Gizmo
|
|
16
15
|
NilResponseError = Class.new(GizmoError)
|
17
16
|
|
18
17
|
end
|
18
|
+
|
19
19
|
require "gizmo/configuration"
|
20
20
|
require "gizmo/extras"
|
data/lib/gizmo/extras.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# Override the #extended method on Module so it calls a method
|
2
|
+
# #extended_with if it exists - we use this to manage an array
|
3
|
+
# of modules that have been mixed in to a Gizmo::Page object
|
4
|
+
class Module
|
5
|
+
def extended mixin
|
6
|
+
mixin.extended_with(self) if mixin.respond_to?(:extended_with)
|
7
|
+
end
|
6
8
|
end
|
data/lib/gizmo/helpers.rb
CHANGED
@@ -4,7 +4,6 @@ module Gizmo
|
|
4
4
|
|
5
5
|
def on_page &block
|
6
6
|
raise NilResponseError, "Doh! response object is nil. This generally means your scenario has not yet visited a page!" if response.nil?
|
7
|
-
raise ArgumentError, 'You must supply a block argument' unless block.is_a? Proc
|
8
7
|
yield Page.new(self, response.body, current_url)
|
9
8
|
end
|
10
9
|
|
@@ -13,20 +12,29 @@ module Gizmo
|
|
13
12
|
on_page do |page|
|
14
13
|
module_names.each do |module_name|
|
15
14
|
raise ArgumentError, 'module_name must be a symbol' unless module_name.is_a?(Symbol)
|
16
|
-
|
17
|
-
begin
|
18
|
-
require "#{Gizmo.configuration.mixin_dir}/page_with_#{module_name}.rb" unless Object.const_defined?(const_name)
|
19
|
-
rescue LoadError
|
20
|
-
raise MixinNotFoundError, "Expected a page mixin file at #{Gizmo.configuration.mixin_dir}/page_with_#{module_name}.rb generate one with gizmo -g #{module_name}"
|
21
|
-
end
|
22
|
-
page.extend(Object.const_get(const_name))
|
23
|
-
raise MixinNotValidError, "Page did not have #{module_name} at #{page.url}" unless page.valid?
|
24
|
-
page.mixins << module_name
|
15
|
+
add_mixin_to_page page, module_name
|
25
16
|
end
|
26
17
|
yield page if block_given?
|
27
18
|
end
|
28
19
|
end
|
29
20
|
|
21
|
+
private
|
22
|
+
|
23
|
+
def load_mixin! mixin_name
|
24
|
+
begin
|
25
|
+
const_name = "PageWith#{mixin_name.to_s.camelize}"
|
26
|
+
require "#{Gizmo.configuration.mixin_dir}/page_with_#{mixin_name}.rb" unless Object.const_defined?(const_name)
|
27
|
+
Object.const_get(const_name)
|
28
|
+
rescue LoadError
|
29
|
+
raise MixinNotFoundError, "Expected a page mixin file at #{Gizmo.configuration.mixin_dir}/page_with_#{mixin_name}.rb generate one with `gizmo -g #{mixin_name}`"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_mixin_to_page page, mixin_name
|
34
|
+
page.extend(load_mixin!(mixin_name))
|
35
|
+
raise MixinNotValidError, "Page did not have #{mixin_name} at #{page.url}" unless page.valid?
|
36
|
+
end
|
37
|
+
|
30
38
|
end
|
31
39
|
|
32
40
|
end
|
data/lib/gizmo/page.rb
CHANGED
@@ -4,6 +4,10 @@ module Gizmo
|
|
4
4
|
|
5
5
|
attr_reader :mixins, :url, :document
|
6
6
|
|
7
|
+
def extended_with base
|
8
|
+
@mixins << base
|
9
|
+
end
|
10
|
+
|
7
11
|
def initialize driver, content, url
|
8
12
|
@mixins = []
|
9
13
|
@browser = driver
|
@@ -25,6 +29,14 @@ module Gizmo
|
|
25
29
|
@document.css(css_selector).length > 0
|
26
30
|
end
|
27
31
|
|
32
|
+
private
|
33
|
+
|
34
|
+
def element_struct
|
35
|
+
open_struct = OpenStruct.new
|
36
|
+
yield open_struct if block_given?
|
37
|
+
open_struct
|
38
|
+
end
|
39
|
+
|
28
40
|
end
|
29
41
|
|
30
42
|
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
# Dir[File.dirname(__FILE__) + '/../features/support/pages/*'].each do |path|
|
4
|
-
# require path if path =~ /page_with.+\.rb$/
|
5
|
-
# end
|
6
|
-
|
7
3
|
require 'capybara'
|
8
4
|
require 'capybara/dsl'
|
9
5
|
require File.expand_path(File.dirname(__FILE__) + '/../features/support/patches/capybara')
|
data/spec/gizmo/extras_spec.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Gizmo" do
|
4
|
-
|
4
|
+
|
5
5
|
describe "Extras" do
|
6
|
-
|
7
|
-
it "should provide an override for OpenStruct to make it yield to a block" do
|
8
|
-
OpenStruct { |o| o.should be_an OpenStruct }
|
9
|
-
end
|
10
6
|
|
11
|
-
it "should
|
12
|
-
|
7
|
+
it "should override #extended in the base Module class" do
|
8
|
+
Module.new.should respond_to :extended
|
13
9
|
end
|
14
|
-
|
10
|
+
|
15
11
|
end
|
16
|
-
|
12
|
+
|
17
13
|
end
|
data/spec/gizmo/helpers_spec.rb
CHANGED
@@ -36,7 +36,7 @@ describe "Gizmo" do
|
|
36
36
|
|
37
37
|
describe "#on_page" do
|
38
38
|
it "should raise an error if no block given" do
|
39
|
-
lambda { on_page }.should raise_error(
|
39
|
+
lambda { on_page }.should raise_error("no block given")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should not raise an error if given a block" do
|
@@ -77,7 +77,7 @@ describe "Gizmo" do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should raise Gizmo::MixinNotFoundError if the mixin file cannot be loaded from the mixin_path" do
|
80
|
-
lambda { on_page_with :my_non_existent_mixin }.should raise_error(Gizmo::MixinNotFoundError, "Expected a page mixin file at /
|
80
|
+
lambda { on_page_with :my_non_existent_mixin }.should raise_error(Gizmo::MixinNotFoundError, "Expected a page mixin file at #{Gizmo.configuration.mixin_dir}/page_with_my_non_existent_mixin.rb generate one with `gizmo -g my_non_existent_mixin`")
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should yield a page object to a block if supplied" do
|
@@ -94,11 +94,6 @@ describe "Gizmo" do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
it "should add the mixin name to the Page's mixin instance attribute" do
|
98
|
-
on_page_with(:my_mixin, :my_other_mixin) do |page|
|
99
|
-
[:my_mixin, :my_other_mixin].each { |mixin| page.mixins.should include mixin }
|
100
|
-
end
|
101
|
-
end
|
102
97
|
end
|
103
98
|
end
|
104
99
|
end
|
data/spec/gizmo/page_spec.rb
CHANGED
@@ -96,6 +96,16 @@ describe "Gizmo" do
|
|
96
96
|
|
97
97
|
end
|
98
98
|
|
99
|
+
describe "#extended_with" do
|
100
|
+
|
101
|
+
it "should add the mixin name to the Page's @mixin instance attribute" do
|
102
|
+
on_page_with(:my_mixin, :my_other_mixin) do |page|
|
103
|
+
[:my_mixin, :my_other_mixin].each { |m| page.mixins.should include Object.const_get("PageWith#{m.to_s.camelize}") }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
99
109
|
describe "#has_selector?" do
|
100
110
|
|
101
111
|
it "should return true if @document contains one or more elements matching the selector" do
|
@@ -109,6 +119,18 @@ describe "Gizmo" do
|
|
109
119
|
|
110
120
|
end
|
111
121
|
|
122
|
+
describe "#element_struct" do
|
123
|
+
|
124
|
+
it "should provide an override for OpenStruct to make it yield to a block" do
|
125
|
+
@page.send(:element_struct) { |o| o.should be_an OpenStruct }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return an OpenStruct if not given a block" do
|
129
|
+
@page.send(:element_struct).should be_an OpenStruct
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
112
134
|
end
|
113
135
|
|
114
136
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Luke Cunningham
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-04-10 00:00:00 +10:00
|
20
20
|
default_executable: gizmo
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -76,9 +76,23 @@ dependencies:
|
|
76
76
|
type: :development
|
77
77
|
version_requirements: *id004
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: metric_fu
|
80
80
|
prerelease: false
|
81
81
|
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 1
|
87
|
+
- 3
|
88
|
+
- 0
|
89
|
+
version: 1.3.0
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: nokogiri
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
82
96
|
requirements:
|
83
97
|
- - ">="
|
84
98
|
- !ruby/object:Gem::Version
|
@@ -88,11 +102,11 @@ dependencies:
|
|
88
102
|
- 1
|
89
103
|
version: 1.4.1
|
90
104
|
type: :runtime
|
91
|
-
version_requirements: *
|
105
|
+
version_requirements: *id006
|
92
106
|
- !ruby/object:Gem::Dependency
|
93
107
|
name: activesupport
|
94
108
|
prerelease: false
|
95
|
-
requirement: &
|
109
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
96
110
|
requirements:
|
97
111
|
- - ">="
|
98
112
|
- !ruby/object:Gem::Version
|
@@ -102,7 +116,7 @@ dependencies:
|
|
102
116
|
- 5
|
103
117
|
version: 2.3.5
|
104
118
|
type: :runtime
|
105
|
-
version_requirements: *
|
119
|
+
version_requirements: *id007
|
106
120
|
description: gizmo is a simple page model testing framework used and sponsored by 'realestate.com.au'. The aim of the project is to DRY up your testing assertions by abstracting code that defines your page resulting in a consistent, easy to maintain test suit
|
107
121
|
email: luke@icaruswings.com
|
108
122
|
executables:
|
@@ -111,17 +125,17 @@ extensions: []
|
|
111
125
|
|
112
126
|
extra_rdoc_files:
|
113
127
|
- LICENSE
|
114
|
-
- README.
|
128
|
+
- README.markdown
|
115
129
|
files:
|
116
130
|
- .document
|
117
131
|
- .gitignore
|
118
132
|
- LICENSE
|
119
|
-
- README.
|
133
|
+
- README.markdown
|
120
134
|
- Rakefile
|
121
135
|
- VERSION
|
122
136
|
- bin/gizmo
|
123
|
-
- features/
|
124
|
-
- features/step_definitions/
|
137
|
+
- features/github_example.feature
|
138
|
+
- features/step_definitions/github_example_steps.rb
|
125
139
|
- features/support/env.rb
|
126
140
|
- features/support/pages/page_with_github_repo_details.rb
|
127
141
|
- features/support/pages/page_with_github_search.rb
|
data/features/gizmo.feature
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
Feature:
|
2
|
-
As a behaviour driven developer
|
3
|
-
In order to have a DRY, elegant and maintainable test suite
|
4
|
-
I want 'gizmo' to do it's funky thing
|
5
|
-
|
6
|
-
Scenario: A scenario performs a github search
|
7
|
-
Given the scenario is on the github homepage
|
8
|
-
When the scenario enters "gizmo" into the search box
|
9
|
-
And the scenario clicks the magnifying glass icon
|
10
|
-
And the scenario clicks on the "icaruswings / gizmo" link
|
11
|
-
Then the scenario is on the "gizmo" github repository details page
|
12
|
-
And the scenario is on a github repository details page which belongs to "icaruswings"
|