symbiont 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .bundle/*
2
+ output/*
3
+ .idea/*
4
+ pkg/*
5
+ *.gem
6
+ *.swo
7
+ *.swp
8
+ .DS_Store
9
+ Gemfile.lock
10
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in symbiont.gemspec
4
+ gemspec
data/HISTORY.md ADDED
@@ -0,0 +1,7 @@
1
+ Change Log and History
2
+ ======================
3
+
4
+ Version 0.0.1 / 2012-03-02
5
+ --------------------------
6
+
7
+ This is a bare implementation of the Symbiont library. The Symbiont library is one part of what will be the Lucid testing framework. This release does nothing beyond establishing the gem and providing some basis for how the library will work.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright © 2012 Jeff Nyman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ Symbiont
2
+ ========
3
+
4
+ Description
5
+ -----------
6
+
7
+ The Symbiont gem is designed to provide an open framework for running automated tests against a browser using popular web testing interfaces.
8
+
9
+
10
+ Meaning
11
+ -------
12
+
13
+ A "symbiont" is an organism in a symbiotic (mutually beneficial) relationship. Some of these relationships are called _obligate_, which means that both organisms need each other in order to survive. Other such relationships are called _facultative_, meaning that both organisms don't strictly need each other to survive, but they stand a better chance if they do.
14
+
15
+ Symbiotic relationships include associations in which one organism lives on another organism -- _ectosymbiosis_ -- or where one organism lives inside the other -- _endosymbiosis_.
16
+
17
+ So, with that bit of context, think of this gem as a facultative, endosymbiotic organism that lives within your test logic, giving it strength and sustenance.
18
+
19
+
20
+ Copyright
21
+ ---------
22
+
23
+ See the LICENSE file for details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new do |c|
5
+ options = ["--color"]
6
+ options += ["--format", "documentation"]
7
+ options += ["--format", "nested", "--out output/rspec-report.txt"]
8
+ options += ["--format", "html", "--out output/rspec-report.html"]
9
+ c.rspec_opts = options
10
+ end
11
+
12
+ namespace :spec do
13
+ desc "Get code coverage for spec execution"
14
+ RSpec::Core::RakeTask.new('cov') do |c|
15
+ ENV['COVERAGE'] = "on"
16
+ end
17
+ end
18
+
19
+ task :default => :spec
@@ -0,0 +1,19 @@
1
+ module Symbiont
2
+ module Generators
3
+
4
+ # This method allows for a url_is() method in definitions that will
5
+ # define a direct means of accessing a resource. The most common
6
+ # example will be a URL for a web page, but any URI is valid. The
7
+ # URL provided can be navigated to using the generated view() method
8
+ # on a definition instance.
9
+ #
10
+ # @param [String] url the resource identifier to access
11
+ # @return [Nil]
12
+ def url_is(url)
13
+ define_method("view") do
14
+ @platform.visit(url)
15
+ end
16
+ end
17
+
18
+ end # module: Generators
19
+ end # module: Symbiont
@@ -0,0 +1,21 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module SeleniumWebDriver
4
+
5
+ class PlatformObject
6
+
7
+ def initialize(browser)
8
+ @browser = browser
9
+ end
10
+
11
+ # Platform method to make a call to a specified URL.
12
+ # See Symbiont::Generators#url_is
13
+ def visit(url)
14
+ @browser.navigate.to(url)
15
+ end
16
+
17
+ end # class: PlatformObject
18
+
19
+ end # module: SeleniumWebDriver
20
+ end # module: Platforms
21
+ end # module: Symbiont
@@ -0,0 +1,9 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module SeleniumWebDriver
4
+
5
+ require_relative('platform_selenium/platform_object')
6
+
7
+ end # module: SeleniumWebDriver
8
+ end # module: Platforms
9
+ end # module: Symbiont
@@ -0,0 +1,21 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+
5
+ class PlatformObject
6
+
7
+ def initialize(browser)
8
+ @browser = browser
9
+ end
10
+
11
+ # Platform method to make a call to a specified URL.
12
+ # See Symbiont::Generators#url_is
13
+ def visit(url)
14
+ @browser.goto(url)
15
+ end
16
+
17
+ end # class: PlatformObject
18
+
19
+ end # module: WatirWebDriver
20
+ end # module: Platforms
21
+ end # module: Symbiont
@@ -0,0 +1,9 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+
5
+ require_relative 'platform_watir/platform_object'
6
+
7
+ end # module: WatirWebDriver
8
+ end # module: Platforms
9
+ end # module: Symbiont
@@ -0,0 +1,24 @@
1
+ module Symbiont
2
+ module Platforms
3
+
4
+ require 'watir-webdriver'
5
+ require 'selenium-webdriver'
6
+
7
+ # This module determines what execution platform Symbiont will use.
8
+ # The decision is based on the browser that has been established for
9
+ # the execution profile
10
+ def get_platform_for(browser)
11
+ if browser.is_a?(Watir::Browser)
12
+ return @platform = Symbiont::Platforms::WatirWebDriver::PlatformObject.new(@browser)
13
+ elsif browser.is_a?(Selenium::WebDriver::Driver)
14
+ return @platform = Symbiont::Platforms::SeleniumWebDriver::PlatformObject.new(@browser)
15
+ else
16
+ raise "Unable to create a platform object for #{browser}"
17
+ end
18
+ end
19
+
20
+ end # module: Platforms
21
+ end # module: Symbiont
22
+
23
+ require_relative 'platform_watir'
24
+ require_relative 'platform_selenium'
@@ -0,0 +1,3 @@
1
+ module Symbiont
2
+ VERSION = "0.0.1"
3
+ end
data/lib/symbiont.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'symbiont/version'
2
+ require 'symbiont/platforms'
3
+ require 'symbiont/generators'
4
+
5
+ module Symbiont
6
+ include Platforms
7
+
8
+ # Used to make a platform object accessible. Will hold object
9
+ # references like these:
10
+ # <Symbiont::Platforms::WatirWebDriver::PlatformObject:0x2cbe8a0>
11
+ # <Symbiont::Platforms::SeleniumWebDriver::PlatformObject:0x2cb9608>
12
+ attr_reader :platform
13
+
14
+ def self.version
15
+ "Symbiont v#{Symbiont::VERSION}"
16
+ end
17
+
18
+ # The included callback is used to provide the core functionality of the
19
+ # library to any class or module that includes the Symbiont library. The
20
+ # calling class or module is extended with logic that the library makes
21
+ # available as class methods. Those methods will be available only in
22
+ # the context of the class (definition) that included Symbiont.
23
+ def self.included(caller)
24
+ puts("#{caller.class} #{caller} attached the Symbiont")
25
+ caller.extend Symbiont::Generators
26
+ end
27
+
28
+ # The initialize method will be invoked when a page definition includes
29
+ # Symbiont. Some key things are happening here that are critical to
30
+ # Symbiont working correctly:
31
+ # (1) A browser instance is being created.
32
+ # (2) A platform object is created for that browser.
33
+ #
34
+ # @param [Object] browser a browser instance with a tool driver
35
+ def initialize(browser)
36
+ puts("Symbiont attached to browser: #{browser}")
37
+ @browser = browser
38
+ establish_platform_object_for(browser)
39
+ end
40
+
41
+ private
42
+
43
+ # This method is crucial in that it sets up the platform instance that
44
+ # will be used by just about every module that makes calls to any
45
+ # platform-specific functionality.
46
+ #
47
+ # @param [Object] browser a browser instance with a tool driver
48
+ def establish_platform_object_for(browser)
49
+ @platform = get_platform_for(browser)
50
+ end
51
+
52
+ end
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+
3
+ require 'watir-webdriver'
4
+
5
+ require 'simplecov'
6
+
7
+ SimpleCov.start do
8
+ add_filter "/spec/"
9
+ coverage_dir "output/coverage"
10
+ end if ENV['COVERAGE']
11
+
12
+ require 'symbiont'
13
+
14
+ class DefinitionTest
15
+ include Symbiont
16
+
17
+ url_is "http://localhost:4567"
18
+ end
19
+
20
+ def mock_browser_for_watir
21
+ watir_browser = double('watir')
22
+ watir_browser.stub(:is_a?).with(Watir::Browser).and_return(true)
23
+ watir_browser.stub(:is_a?).with(Selenium::WebDriver::Driver).and_return(false)
24
+ watir_browser
25
+ end
26
+
27
+ def mock_browser_for_selenium
28
+ selenium_browser = double('selenium')
29
+ selenium_browser.stub(:is_a?).with(Watir::Browser).and_return(false)
30
+ selenium_browser.stub(:is_a?).with(Selenium::WebDriver::Driver).and_return(true)
31
+ selenium_browser
32
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbiont::Generators do
4
+ let(:watir_browser) { mock_browser_for_watir }
5
+ let(:selenium_browser) { mock_browser_for_selenium }
6
+ let(:watir_definition) { DefinitionTest.new(watir_browser) }
7
+ let(:selenium_definition) { DefinitionTest.new(selenium_browser) }
8
+
9
+ context "a definition using watir-webdriver" do
10
+ describe "providing a url" do
11
+ it "should navigate to the page when viewed" do
12
+ watir_browser.should_receive(:goto)
13
+ watir_definition.view
14
+ end
15
+ end
16
+ end
17
+
18
+ context "a definition using selenium-webdriver" do
19
+ describe "providing a url" do
20
+ it "should navigate to the page when viewed" do
21
+ selenium_browser.should_receive(:navigate).and_return(selenium_browser)
22
+ selenium_browser.should_receive(:to)
23
+ selenium_definition.view
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbiont do
4
+
5
+ let(:watir_browser) { mock_browser_for_watir }
6
+ let(:selenium_browser) { mock_browser_for_selenium }
7
+ let(:watir_definition) { DefinitionTest.new(watir_browser) }
8
+ let(:selenium_definition) { DefinitionTest.new(selenium_browser) }
9
+
10
+ context "a definition using watir-webdriver" do
11
+ it "should return a watir platform object" do
12
+ watir_definition.platform.should be_kind_of Symbiont::Platforms::WatirWebDriver::PlatformObject
13
+ end
14
+ end
15
+
16
+ context "a definition using selenium-webdriver" do
17
+ it "should return a selenium platform object" do
18
+ selenium_definition.platform.should be_kind_of Symbiont::Platforms::SeleniumWebDriver::PlatformObject
19
+ end
20
+ end
21
+
22
+ context "an unrecognized browser" do
23
+ it "should raise an exception" do
24
+ expect { DefinitionTest.new(:unknown_browser) }.to raise_error
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbiont do
4
+ it "returns version information" do
5
+ Symbiont.version.should == "Symbiont v#{Symbiont::VERSION}"
6
+ end
7
+ end
data/symbiont.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "symbiont/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "symbiont"
7
+ s.version = Symbiont::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.license = "MIT"
10
+ s.authors = ["Jeff Nyman"]
11
+ s.email = ["jeffnyman@gmail.com"]
12
+ s.homepage = "https://github.com/jnyman/symbiont"
13
+ s.summary = %q{An endosymbiotic facultative library for web application testing.}
14
+ s.description = %q{An endosymbiotic facultative library for web application testing.}
15
+
16
+ s.required_ruby_version = '>= 1.9.2'
17
+ s.rubyforge_project = "symbiont"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,specs,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_development_dependency 'rspec', '>= 2.8.0'
25
+ s.add_development_dependency 'simplecov', '>= 0.6.1'
26
+
27
+ s.add_runtime_dependency 'watir-webdriver', '0.5.3'
28
+ s.add_runtime_dependency 'selenium-webdriver', '2.20.0'
29
+ end
data/test/base.rb ADDED
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+
3
+ require 'watir-webdriver'
4
+ require 'symbiont'
5
+
6
+ class Login
7
+ include Symbiont
8
+ end
9
+
10
+ @browser_watir = Watir::Browser.new(:firefox)
11
+ watir_test = Login.new(@browser_watir)
12
+
13
+ @browser_selenium = Selenium::WebDriver.for(:firefox)
14
+ selenium_test = Login.new(@browser_selenium)
15
+
16
+ @browser_watir.close
17
+ @browser_selenium.close
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+
3
+ require 'symbiont'
4
+
5
+ class Login
6
+ include Symbiont
7
+
8
+ url_is "http://localhost:4567"
9
+ end
10
+
11
+ @browser_selenium = Selenium::WebDriver.for(:firefox)
12
+ selenium_test = Login.new(@browser_selenium)
13
+ selenium_test.view
14
+
15
+ @browser_selenium.close
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+
3
+ require 'symbiont'
4
+
5
+ class Login
6
+ include Symbiont
7
+
8
+ url_is "http://localhost:4567"
9
+ end
10
+
11
+ @browser_watir = Watir::Browser.new(:firefox)
12
+ watir_test = Login.new(@browser_watir)
13
+ watir_test.view
14
+
15
+ @browser_watir.close
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: symbiont
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Nyman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &21048780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *21048780
25
+ - !ruby/object:Gem::Dependency
26
+ name: simplecov
27
+ requirement: &21048504 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.6.1
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *21048504
36
+ - !ruby/object:Gem::Dependency
37
+ name: watir-webdriver
38
+ requirement: &21048228 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.3
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *21048228
47
+ - !ruby/object:Gem::Dependency
48
+ name: selenium-webdriver
49
+ requirement: &28582476 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - =
53
+ - !ruby/object:Gem::Version
54
+ version: 2.20.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *28582476
58
+ description: An endosymbiotic facultative library for web application testing.
59
+ email:
60
+ - jeffnyman@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - HISTORY.md
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - lib/symbiont.rb
72
+ - lib/symbiont/generators.rb
73
+ - lib/symbiont/platform_selenium.rb
74
+ - lib/symbiont/platform_selenium/platform_object.rb
75
+ - lib/symbiont/platform_watir.rb
76
+ - lib/symbiont/platform_watir/platform_object.rb
77
+ - lib/symbiont/platforms.rb
78
+ - lib/symbiont/version.rb
79
+ - spec/spec_helper.rb
80
+ - spec/symbiont/generators_spec.rb
81
+ - spec/symbiont/platform_object_spec.rb
82
+ - spec/symbiont/symbiont_spec.rb
83
+ - symbiont.gemspec
84
+ - test/base.rb
85
+ - test/symbiont_selenium.rb
86
+ - test/symbiont_watir.rb
87
+ homepage: https://github.com/jnyman/symbiont
88
+ licenses:
89
+ - MIT
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 1.9.2
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project: symbiont
108
+ rubygems_version: 1.8.17
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: An endosymbiotic facultative library for web application testing.
112
+ test_files: []
113
+ has_rdoc: