spec/symbiont/factory_spec.rb in symbiont-0.2.1 vs spec/symbiont/factory_spec.rb in symbiont-0.3.0
- old
+ new
@@ -1,174 +1,114 @@
require 'spec_helper'
-require 'symbiont/factory'
-module AppModule
- class TestDefinitionInModule
- include Symbiont
- url_is "http://localhost:9292"
- end
-end
-
-class TestFactory
- include Symbiont::Factory
-
- attr_accessor :browser
- attr_accessor :active
-end
-
-class TestFactoryPage
- include Symbiont
-
- url_is "http://localhost:9292"
-end
-
-class TestFactoryWithURL
- include Symbiont
-
- url_is "http://localhost:9292"
-end
-
-class TestFactorySecond
- include Symbiont
-end
-
-class TestFactoryThird
- include Symbiont
-end
-
describe Symbiont::Factory do
before(:each) do
@factory = TestFactory.new
- @factory.browser = mock_browser_for_watir
+ @factory.driver = mock_browser_for_watir
end
- it "should create a new definition object, using on" do
- @factory.browser.should_not_receive(:goto)
- @factory.on DefinitionTest do |page|
- page.should be_instance_of DefinitionTest
- end
+ it 'will create a new definition and view it, using on_view' do
+ @factory.driver.should_receive(:goto)
+ @factory.on_view(ValidPage)
+ end
- @factory.on "DefinitionTest" do |page|
- page.should be_instance_of DefinitionTest
+ it 'will create a new definition and view it, using on_view and a block' do
+ @factory.driver.should_receive(:goto)
+ @factory.on_view ValidPage do |page|
+ page.should be_instance_of ValidPage
end
+ end
- @factory.on "AppModule::TestDefinitionInModule" do |page|
- page.should be_instance_of AppModule::TestDefinitionInModule
+ it 'will create a new definition, using on and a block with a parameter' do
+ @factory.driver.should_not_receive(:goto)
+ @factory.on ValidPage do |page|
+ page.should be_instance_of ValidPage
end
end
- it "should create a new definition object, using during" do
- @factory.browser.should_not_receive(:goto)
- @factory.during DefinitionTest do |page|
- page.should be_instance_of DefinitionTest
+ it 'will create a new definition, using on and a block without a parameter' do
+ @factory.driver.should_not_receive(:goto)
+ @factory.on ValidPage do
+ @factory.active.should be_instance_of ValidPage
end
+ end
- @factory.during "DefinitionTest" do |page|
- page.should be_instance_of DefinitionTest
- end
+ it 'will use an existing object reference with on' do
+ @factory.driver.should_receive(:goto)
+ obj1 = @factory.on_view ValidPage
+ obj2 = @factory.on ValidPage
+ obj1.should == obj2
+ end
- @factory.during "AppModule::TestDefinitionInModule" do |page|
- page.should be_instance_of AppModule::TestDefinitionInModule
- end
+ it 'will not use an existing object reference with on_new' do
+ @factory.driver.should_receive(:goto)
+ obj1 = @factory.on_view ValidPage
+ obj2 = @factory.on_new ValidPage
+ obj1.should_not == obj2
end
- it "should create a new definition object and view it, using on_view" do
- @factory.browser.should_receive(:goto).exactly(5).times
- @factory.on_view DefinitionTest do |page|
- page.should be_instance_of DefinitionTest
+ it 'will create a new definition, using on_set' do
+ @factory.driver.should_not_receive(:goto)
+ @factory.on_set ValidPage do |page|
+ page.should be_instance_of ValidPage
end
+ end
- @factory.on_view "DefinitionTest" do |page|
- page.should be_instance_of DefinitionTest
- end
-
- @factory.on_view "AppModule::TestDefinitionInModule" do |page|
- page.should be_instance_of AppModule::TestDefinitionInModule
- end
+ it 'will set a reference to be used outside the factory' do
+ active = @factory.on ValidPage
+ current = @factory.instance_variable_get '@active'
+ current.should === active
end
- it "should create a new definition object and view it, using start_activity" do
- @factory.browser.should_receive(:goto).exactly(5).times
- @factory.start_activity DefinitionTest do |page|
- page.should be_instance_of DefinitionTest
- end
-
- @factory.start_activity "DefinitionTest" do |page|
- page.should be_instance_of DefinitionTest
- end
-
- @factory.start_activity "AppModule::TestDefinitionInModule" do |page|
- page.should be_instance_of AppModule::TestDefinitionInModule
- end
+ it 'will use an existing object reference with on_set' do
+ @factory.driver.should_receive(:goto)
+ obj1 = @factory.on_view ValidPage
+ obj2 = @factory.on_set ValidPage
+ obj1.should == obj2
end
- it "should create a new definition object and view it, using start_on" do
- @factory.browser.should_receive(:goto).exactly(5).times
- @factory.start_on DefinitionTest do |page|
- page.should be_instance_of DefinitionTest
+ it 'will use an existing context using on after using on_set' do
+ @factory.on_set ValidPage do |page|
+ @obj1 = page # obj1 is CONTEXT, ACTIVE
end
- @factory.start_on "DefinitionTest" do |page|
- page.should be_instance_of DefinitionTest
+ @factory.on ValidPageNewContext do |page|
+ @obj2 = page # obj2 is ACTIVE
end
- @factory.start_on "AppModule::TestDefinitionInModule" do |page|
- page.should be_instance_of AppModule::TestDefinitionInModule
+ @factory.on ValidPage do |page|
+ @obj3 = page # obj1 CONTEXT is still set
end
- end
- it "should set a reference to be used outside the factory" do
- active = @factory.on DefinitionTest
- current = @factory.instance_variable_get "@active"
- current.should === active
+ @obj1.should_not == @obj2
+ @obj1.should == @obj3
end
- it "should use an existing definition when that definition is already active" do
- @factory.instance_variable_set "@active", TestFactorySecond.new(@factory.browser)
-
- used = false
- @factory.if_on(TestFactorySecond) do |page|
- page.should be_instance_of TestFactorySecond
- used = true
+ it 'will use an existing context using on_new of a different class after using on_set' do
+ @factory.on_set ValidPage do |page|
+ @obj1 = page # obj1 is CONTEXT, ACTIVE
end
- used.should be true
- used = false
- @factory.if_on("TestFactorySecond") do |page|
- page.should be_instance_of TestFactorySecond
- used = true
+ @factory.on_new ValidPageNewContext do |page|
+ @obj2 = page # ACTIVE nil, obj1 no longer ACTIVE, but is CONTEXT
end
- used.should be true
- used = false
- @factory.instance_variable_set "@active", AppModule::TestDefinitionInModule.new(@factory.browser)
- @factory.if_on("AppModule::TestDefinitionInModule") do |page|
- page.should be_instance_of AppModule::TestDefinitionInModule
- used = true
+ @factory.on ValidPage do |page|
+ @obj3 = page # CONTEXT is set to obj1
end
- used.should be true
+
+ @obj1.should_not == @obj2
+ @obj1.should == @obj3
end
- it "should not execute block if definition is not the active definition" do
- @factory.instance_variable_set "@active", TestFactorySecond.new(@factory.browser)
- @factory.if_on(TestFactoryThird) do |page|
- fail
+ it 'will clear existing context using on_new after using on_set' do
+ @factory.on_set ValidPage do |page|
+ @obj1 = page # obj1 is CONTEXT, ACTIVE
end
- @factory.if_on("TestFactoryThird") do |page|
- fail
+ @factory.on_new ValidPage do |page|
+ @obj2 = page # ACTIVE nil; since page is same, CONTEXT is nil
end
- @factory.if_on("AppModule::TestDefinitionInModule") do |page|
- fail
- end
+ @obj1.should_not == @obj2
end
-
- it "should return the @active instance if asking for another page" do
- expected = TestFactoryWithURL.new(@factory.browser)
- @factory.instance_variable_set "@active", expected
- @factory.if_on(TestFactoryPage).should == expected
- @factory.if_on("TestFactoryPage").should == expected
- @factory.if_on("AppModule::TestDefinitionInModule").should == expected
- end
-
-end
\ No newline at end of file
+end