Cucumber rails2 v0.3.3 #213

Closed
wants to merge 3 commits into
from
View
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{cucumber-rails}
- s.version = "0.3.2"
+ s.version = "0.3.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Dennis Bl\303\266te", "Aslak Helles\303\270y", "Rob Holland"]
@@ -97,7 +97,7 @@ Gem::Specification.new do |s|
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<cucumber>, [">= 0.8.0"])
+ s.add_runtime_dependency(%q<cucumber>, ["~> 1.1.0"])
s.add_development_dependency(%q<aruba>, [">= 0.1.9"])
else
s.add_dependency(%q<cucumber>, [">= 0.8.0"])
@@ -10,21 +10,21 @@ def self.included(base)
def click_with_javascript_emulation
if link_with_non_get_http_method?
- Capybara::Driver::RackTest::Form.new(driver, js_form(self[:href], emulated_method)).submit(self)
+ Capybara::RackTest::Form.new(driver, js_form(element_node.document, self[:href], emulated_method)).submit(self)
else
click_without_javascript_emulation
end
end
private
- def js_form(action, emulated_method, method = 'POST')
- js_form = node.document.create_element('form')
+ def js_form(document, action, emulated_method, method = 'POST')
+ js_form = document.create_element('form')
js_form['action'] = action
js_form['method'] = method
if emulated_method and emulated_method.downcase != method.downcase
- input = node.document.create_element('input')
+ input = document.create_element('input')
input['type'] = 'hidden'
input['name'] = '_method'
input['value'] = emulated_method
@@ -36,37 +36,46 @@ def js_form(action, emulated_method, method = 'POST')
def link_with_non_get_http_method?
if ::Rails.version.to_f >= 3.0
- tag_name == 'a' && node['data-method'] && node['data-method'] =~ /(?:delete|put|post)/
+ tag_name == 'a' && element_node['data-method'] && element_node['data-method'] =~ /(?:delete|put|post)/
else
- tag_name == 'a' && node['onclick'] && node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
+ tag_name == 'a' && element_node['onclick'] && element_node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
end
end
def emulated_method
if ::Rails.version.to_f >= 3.0
- node['data-method']
+ element_node['data-method']
else
- node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
+ element_node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
+ end
+ end
+
+ def element_node
+ if self.respond_to? :native
+ self.native
+ else
+ warn "DEPRECATED: cucumber-rails loves you, just not your version of Capybara. Please update Capybara to >= 0.4.0"
+ self.node
end
end
end
end
end
-class Capybara::Driver::RackTest::Node
+class Capybara::RackTest::Node
include Cucumber::Rails::CapybaraJavascriptEmulation
end
Before('~@no-js-emulation') do
# Enable javascript emulation
- Capybara::Driver::RackTest::Node.class_eval do
+ Capybara::RackTest::Node.class_eval do
alias_method :click, :click_with_javascript_emulation
end
end
Before('@no-js-emulation') do
# Disable javascript emulation
- Capybara::Driver::RackTest::Node.class_eval do
+ Capybara::RackTest::Node.class_eval do
alias_method :click, :click_without_javascript_emulation
end
end