1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Expose current_scope as a session DSL method, closes #959

This commit is contained in:
Martijn Walraven 2013-02-17 16:19:26 +01:00
parent e22c937884
commit 0d1a6d687a
2 changed files with 34 additions and 5 deletions

View file

@ -41,7 +41,7 @@ module Capybara
:visit, :within, :within_fieldset, :within_table, :within_frame,
:within_window, :current_path, :save_page, :save_and_open_page,
:save_screenshot, :reset_session!, :response_headers, :status_code,
:title, :has_title?, :has_no_title?
:title, :has_title?, :has_no_title?, :current_scope
]
DSL_METHODS = NODE_METHODS + SESSION_METHODS
@ -350,7 +350,7 @@ module Capybara
NODE_METHODS.each do |method|
define_method method do |*args, &block|
@touched = true
current_node.send(method, *args, &block)
current_scope.send(method, *args, &block)
end
end
@ -380,12 +380,12 @@ module Capybara
return false
end
private
def current_node
def current_scope
scopes.last
end
private
def scopes
@scopes ||= [document]
end

View file

@ -0,0 +1,29 @@
Capybara::SpecHelper.spec '#current_scope' do
before do
@session.visit('/with_scope')
end
context "when not in a #within block" do
it "should return the document" do
@session.current_scope.should be_kind_of Capybara::Node::Document
end
end
context "when in a #within block" do
it "should return the element in scope" do
@session.within(:css, "#simple_first_name") do
@session.current_scope[:name].should eq 'first_name'
end
end
end
context "when in a nested #within block" do
it "should return the element in scope" do
@session.within("//div[@id='for_bar']") do
@session.within(".//input[@value='Peter']") do
@session.current_scope[:name].should eq 'form[first_name]'
end
end
end
end
end