diff --git a/README.rdoc b/README.rdoc index be1ab99f..93d7d4cb 100644 --- a/README.rdoc +++ b/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 diff --git a/lib/capybara/cucumber.rb b/lib/capybara/cucumber.rb index 5a669dca..fe0b83aa 100644 --- a/lib/capybara/cucumber.rb +++ b/lib/capybara/cucumber.rb @@ -3,7 +3,7 @@ require 'capybara' require 'capybara/dsl' require 'capybara/rspec/matchers' -World(Capybara) +World(Capybara::DSL) World(Capybara::RSpecMatchers) After do diff --git a/lib/capybara/dsl.rb b/lib/capybara/dsl.rb index 5aa8d072..e6e75f7f 100644 --- a/lib/capybara/dsl.rb +++ b/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 @@ module Capybara 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 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 - - Session::DSL_METHODS.each do |method| - class_eval <<-RUBY, __FILE__, __LINE__+1 - def #{method}(*args, &block) - page.#{method}(*args, &block) - end - RUBY + ## + # + # 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::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 + end end + extend(Capybara::DSL) end diff --git a/lib/capybara/rspec.rb b/lib/capybara/rspec.rb index c137f833..3ef173f3 100644 --- a/lib/capybara/rspec.rb +++ b/lib/capybara/rspec.rb @@ -5,20 +5,20 @@ require 'capybara/rspec/matchers' 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 diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 2790d3cc..5c584ea6 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -41,7 +41,7 @@ module Capybara :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 ] DSL_METHODS = NODE_METHODS + SESSION_METHODS diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index 8d97b246..b1c21654 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'capybara/dsl' -describe Capybara do +describe Capybara::DSL do before do Capybara.app = TestApp @@ -170,7 +170,7 @@ describe Capybara do 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 @@ describe Capybara do 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 @@ describe Capybara do 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 @@ describe Capybara do 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 diff --git a/spec/rspec/matchers_spec.rb b/spec/rspec/matchers_spec.rb index 4788a2e3..17d5c5ab 100644 --- a/spec/rspec/matchers_spec.rb +++ b/spec/rspec/matchers_spec.rb @@ -5,7 +5,7 @@ require 'capybara/rspec/matchers' Capybara.app = TestApp describe Capybara::RSpecMatchers do - include Capybara + include Capybara::DSL include Capybara::RSpecMatchers describe "have_css matcher" do diff --git a/spec/string_spec.rb b/spec/string_spec.rb index ed9e35e5..f2cb8a93 100644 --- a/spec/string_spec.rb +++ b/spec/string_spec.rb @@ -64,7 +64,7 @@ describe Capybara do 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