Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Separate DSL out into a module

Otherwise we were including a lot of classes in
the namespace of the object that Capybara was
being included in. This could lead to clashes with
some common class names.
  • Loading branch information...
commit 31f1ac3ccb5b173456a2f592f9ecc8c99a4c0694 1 parent 79ff093
@jnicklas authored
View
5 README.rdoc
@@ -418,7 +418,8 @@ correctly waits for the element to disappear from the page.
== Using the DSL in unsupported testing frameworks
-You can mix the DSL into any context by including +Capybara+:
+You can mix the DSL into any context by including +Capybara::DSL+:
+
require 'capybara'
require 'capybara/dsl'
@@ -426,7 +427,7 @@ You can mix the DSL into any context by including +Capybara+:
Capybara.default_driver = :culerity
module MyModule
- include Capybara
+ include Capybara::DSL
def login!
within("//form[@id='session']") do
View
2  lib/capybara/cucumber.rb
@@ -3,7 +3,7 @@
require 'capybara/dsl'
require 'capybara/rspec/matchers'
-World(Capybara)
+World(Capybara::DSL)
World(Capybara::RSpecMatchers)
After do
View
73 lib/capybara/dsl.rb
@@ -1,6 +1,11 @@
require 'capybara'
module Capybara
+ def self.included(base)
+ base.send(:include, Capybara::DSL)
+ warn "`include Capybara` is deprecated please use `include Capybara::DSL` instead."
+ end
+
class << self
attr_writer :default_driver, :current_driver, :javascript_driver, :session_name
@@ -98,42 +103,44 @@ def session_pool
end
end
- extend(self)
+ module DSL
- ##
- #
- # Shortcut to working in a different session. This is useful when Capybara is included
- # in a class or module.
- #
- def using_session(name, &block)
- Capybara.using_session(name, &block)
- end
+ ##
+ #
+ # Shortcut to working in a different session. This is useful when Capybara is included
+ # in a class or module.
+ #
+ def using_session(name, &block)
+ Capybara.using_session(name, &block)
+ end
- ##
- #
- # Shortcut to accessing the current session. This is useful when Capybara is included in a
- # class or module.
- #
- # class MyClass
- # include Capybara
- #
- # def has_header?
- # page.has_css?('h1')
- # end
- # end
- #
- # @return [Capybara::Session] The current session object
- #
- def page
- Capybara.current_session
- end
+ ##
+ #
+ # Shortcut to accessing the current session. This is useful when Capybara is included in a
+ # class or module.
+ #
+ # class MyClass
+ # include Capybara::DSL
+ #
+ # def has_header?
+ # page.has_css?('h1')
+ # end
+ # end
+ #
+ # @return [Capybara::Session] The current session object
+ #
+ def page
+ Capybara.current_session
+ end
- Session::DSL_METHODS.each do |method|
- class_eval <<-RUBY, __FILE__, __LINE__+1
- def #{method}(*args, &block)
- page.#{method}(*args, &block)
- end
- RUBY
+ Session::DSL_METHODS.each do |method|
+ class_eval <<-RUBY, __FILE__, __LINE__+1
+ def #{method}(*args, &block)
+ page.#{method}(*args, &block)
+ end
+ RUBY
+ end
end
+ extend(Capybara::DSL)
end
View
8 lib/capybara/rspec.rb
@@ -5,20 +5,20 @@
require 'capybara/rspec/features'
RSpec.configure do |config|
- config.include Capybara, :type => :request
- config.include Capybara, :type => :acceptance
+ config.include Capybara::DSL, :type => :request
+ config.include Capybara::DSL, :type => :acceptance
config.include Capybara::RSpecMatchers, :type => :request
config.include Capybara::RSpecMatchers, :type => :acceptance
# The before and after blocks must run instantaneously, because Capybara
# might not actually be used in all examples where it's included.
config.after do
- if self.class.include?(Capybara)
+ if self.class.include?(Capybara::DSL)
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
config.before do
- if self.class.include?(Capybara)
+ if self.class.include?(Capybara::DSL)
Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js]
Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver]
end
View
2  lib/capybara/session.rb
@@ -41,7 +41,7 @@ class Session
:body, :html, :current_url, :current_host, :evaluate_script, :source,
:visit, :wait_until, :within, :within_fieldset, :within_table,
:within_frame, :within_window, :current_path, :save_page,
- :save_and_open_page
+ :save_and_open_page, :reset!, :app

The addition of :reset! is causing the path helpers to disappear

After some more research it looks like without this like the :reset! method gets called on actionpack/lib/action_dispatch/testing/integration.rb

With :reset! the method in capybara/capybara/rack_test/driver.rb which sets @browser to nil is called. I believe this is causing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
]
DSL_METHODS = NODE_METHODS + SESSION_METHODS
View
10 spec/dsl_spec.rb
@@ -2,7 +2,7 @@
require 'capybara/dsl'
-describe Capybara do
+describe Capybara::DSL do
before do
Capybara.app = TestApp
@@ -170,7 +170,7 @@
describe 'the DSL' do
before do
- @session = Capybara
+ @session = Class.new { include Capybara::DSL }.new
end
it_should_behave_like "session"
@@ -178,7 +178,7 @@
it "should be possible to include it in another class" do
klass = Class.new do
- include Capybara
+ include Capybara::DSL
end
foo = klass.new
foo.visit('/with_html')
@@ -188,7 +188,7 @@
it "should provide a 'page' shortcut for more expressive tests" do
klass = Class.new do
- include Capybara
+ include Capybara::DSL
end
foo = klass.new
foo.page.visit('/with_html')
@@ -198,7 +198,7 @@
it "should provide an 'using_session' shortcut" do
klass = Class.new do
- include Capybara
+ include Capybara::DSL
end
Capybara.should_receive(:using_session).with(:name)
foo = klass.new
View
2  spec/rspec/matchers_spec.rb
@@ -5,7 +5,7 @@
Capybara.app = TestApp
describe Capybara::RSpecMatchers do
- include Capybara
+ include Capybara::DSL
include Capybara::RSpecMatchers
describe "have_css matcher" do
View
2  spec/string_spec.rb
@@ -64,7 +64,7 @@
string.find('//h1').path.should == '/html/body/div/div[1]/h1'
end
- it "allows finding elements and extracting the path" do
+ it "allows finding elements and extracting the value" do
string.find('//input').value.should == 'bar'
string.find('//select').value.should == 'Capybara'
end

4 comments on commit 31f1ac3

@bcardarella

This commit broke using the Rails path helpers. Not certain what the reason is.

@clayton

@bcardarella I'm experiencing the same thing here

undefined method 'shop_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0x00000101b205f0>

@bcardarella

@clayton I opened a ticket but haven't gotten any feedback from any of the repo collaborators: #323

@jnicklas
Owner

This has now been fixed.

Please sign in to comment.
Something went wrong with that request. Please try again.