Permalink
Browse files

work on v0.0.6

  • Loading branch information...
1 parent 019679a commit 35771a241fa4dcc04d911661af65fe41c65dd8c2 @icaruswings committed Aug 9, 2010
View
@@ -11,13 +11,14 @@ begin
gem.homepage = "http://github.com/icaruswings/gizmo"
gem.authors = ["Luke Cunningham", "Steven Holloway", "Sam Weller"]
gem.add_development_dependency "rspec", ">= 1.3.0"
- gem.add_development_dependency "cucumber", ">= 0.6.3"
+ gem.add_development_dependency "cucumber", ">= 0.7.2"
gem.add_development_dependency "webrat", ">= 0.7.0"
gem.add_development_dependency "capybara", ">= 0.3.5"
gem.add_development_dependency "metric_fu", ">= 1.3.0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
gem.add_dependency "nokogiri", ">= 1.4.1"
gem.add_dependency "activesupport", ">= 2.3.5"
+ gem.add_dependency "tilt", ">= 1.0.1"
end
Jeweler::GemcutterTasks.new
rescue LoadError
View
@@ -5,7 +5,7 @@
#CAPYBARA
require 'capybara/cucumber'
require 'capybara/session'
-require 'features/support/patches/capybara'
+
Capybara.default_driver = :selenium
Capybara.run_server = false
@@ -14,10 +14,28 @@ def search_form
form.submit = container.css("input[alt=search]")
end
end
-
+
+ define_action :enter_search_query do |query|
+ # #set is capybaras method for setting a value for an element
+ locate(search_form.input).set(query)
+ end
+
+ define_action :click_element do |element|
+ locate(element).click
+ end
+
define_action :search do |query|
- fill_in search_form.input.attr('name').value, :with => query
- click search_form.submit.attr('alt').value
+ perform :enter_search_query, query
+ perform :click_element, search_form.submit
+ end
+
+ private
+
+ def locate nokogiri_element
+ # turn a nokogiri element into a capybara element
+ # so we can use capybara's api to perform actions
+ node = nokogiri_element.is_a?(Nokogiri::XML::NodeSet) ? nokogiri_element.first : nokogiri_element
+ find(:xpath, node.path)
end
end
View
@@ -1,6 +1,8 @@
require 'rubygems'
require 'active_support'
require 'nokogiri'
+require 'tilt'
+require 'term/ansicolor'
$LOAD_PATH << File.dirname(__FILE__)
@@ -9,6 +11,7 @@ module Gizmo
autoload :Page, "gizmo/page"
autoload :Helpers, "gizmo/helpers"
autoload :PageMixin, "gizmo/page_mixin"
+ autoload :Templates, "gizmo/templates"
GizmoError = Class.new(StandardError)
MixinNotValidError = Class.new(GizmoError)
View
@@ -35,7 +35,21 @@ def load_mixin! mixin_name
def add_mixin_to_page page, mixin_name
page.extend(load_mixin!(mixin_name))
- raise MixinNotValidError, "Page did not have #{mixin_name} at #{page.url}" unless page.valid?
+ raise MixinNotFoundError, error_body = <<EOS
+
+-------------------------------------------------
+!!! There was no page_with_#{mixin_name} file !!!
+-------------------------------------------------
+You can create a new file at:
+#{mixin_dir}/page_with_#{mixin_name}.rb
+
+then just copy the mixin code below into it
+and you'll be ready to gizmo!
+------------------------------------------------
+
+#{Gizmo::Templates::PageMixin.render(self, :const_name => const_name, :mixin_name => mixin_name)}
+
+EOS
end
end
View
@@ -0,0 +1,9 @@
+module Gizmo
+
+ module Templates
+
+ PageMixin = Tilt.new("#{File.dirname(__FILE__)}/templates/page_mixin.erb")
+
+ end
+
+end
@@ -0,0 +1,27 @@
+module <%= const_name %>
+ # include the Gizmo::PageMixin extensions
+ # you need this to use the define_action syntax
+ include Gizmo::PageMixin
+
+ def valid?
+ # put your code here to test your page is valid
+ # if this method returns false, the on_page_with helper method will raise a "page did not have <%= mixin_name %>"
+ # example.
+ # document.has_selector?("some-css-selector")
+ true
+ end
+
+ # DEFINE YOUR SELECTORS HERE
+ # def search_form
+ # element_struct |form|
+ # form.input = document.css('input[name=search]')
+ # form.input = document.css('input[name=search]')
+ # end
+ # end
+
+ #DEFINE YOUR ACTIONS HERE
+ # define_action :search do |query|
+ # fill_in search_form.input.attr('name'), :with => query
+ # end
+
+end
@@ -77,7 +77,8 @@ def current_url
end
it "should raise Gizmo::MixinNotFoundError if the mixin file cannot be loaded from the mixin_path" do
- 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`")
+ error_msg = Gizmo::Templates::PageMixin.render(self, { :const_name => "PageWithMyNonExistentMixin", :mixin_name => "page_with_my_non_existent_mixin" })
+ lambda { on_page_with :my_non_existent_mixin }.should raise_error(Gizmo::MixinNotFoundError, /#{ error_msg }/)
end
it "should yield a page object to a block if supplied" do

0 comments on commit 35771a2

Please sign in to comment.