mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Initial checkin
This commit is contained in:
commit
8435d19a3a
19 changed files with 423 additions and 0 deletions
4
History.txt
Normal file
4
History.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
=== 0.0.1 2009-11-04
|
||||
|
||||
* 1 major enhancement:
|
||||
* Initial release
|
19
Manifest.txt
Normal file
19
Manifest.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
History.txt
|
||||
Manifest.txt
|
||||
README.rdoc
|
||||
Rakefile
|
||||
examples/webcat.rb
|
||||
lib/webcat.rb
|
||||
lib/webcat/culerity_driver.rb
|
||||
lib/webcat/rack_test_driver.rb
|
||||
lib/webcat/server.rb
|
||||
script/console
|
||||
script/destroy
|
||||
script/generate
|
||||
spec/culerity_driver_spec.rb
|
||||
spec/drivers_spec.rb
|
||||
spec/rack_test_driver_spec.rb
|
||||
spec/spec_helper.rb
|
||||
spec/webcat_spec.rb
|
||||
test/test_helper.rb
|
||||
test/test_webcat.rb
|
49
README.rdoc
Normal file
49
README.rdoc
Normal file
|
@ -0,0 +1,49 @@
|
|||
= webcat
|
||||
|
||||
* http://github.com/jnicklas/webcat
|
||||
|
||||
== DESCRIPTION:
|
||||
|
||||
Webcat is a fledgeling replacement for webrat which aims to work with all
|
||||
browser simulators as well as rack-test.
|
||||
|
||||
== FEATURES/PROBLEMS:
|
||||
|
||||
* FIX (list of features or problems)
|
||||
|
||||
== SYNOPSIS:
|
||||
|
||||
FIX (code sample of usage)
|
||||
|
||||
== REQUIREMENTS:
|
||||
|
||||
* FIX (list of requirements)
|
||||
|
||||
== INSTALL:
|
||||
|
||||
* FIX (sudo gem install, anything else)
|
||||
|
||||
== LICENSE:
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2009 Jonas Nicklas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
Rakefile
Normal file
26
Rakefile
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'rubygems'
|
||||
gem 'hoe', '>= 2.1.0'
|
||||
require 'hoe'
|
||||
require 'fileutils'
|
||||
require './lib/webcat'
|
||||
|
||||
Hoe.plugin :newgem
|
||||
# Hoe.plugin :website
|
||||
# Hoe.plugin :cucumberfeatures
|
||||
|
||||
# Generate all the Rake tasks
|
||||
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
||||
$hoe = Hoe.spec 'webcat' do
|
||||
self.developer 'Jonas Nicklas', 'jonas.nicklas@gmail.com'
|
||||
self.rubyforge_name = self.name # TODO this is default value
|
||||
|
||||
self.extra_deps = [['activesupport','>= 2.0.2']]
|
||||
|
||||
end
|
||||
|
||||
require 'newgem/tasks'
|
||||
Dir['tasks/**/*.rake'].each { |t| load t }
|
||||
|
||||
# TODO - want other tests/tasks run by default? Add them to the list
|
||||
# remove_task :default
|
||||
# task :default => [:spec, :features]
|
36
examples/webcat.rb
Normal file
36
examples/webcat.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
session = Webcat::Session.new('http://localhost:3000')
|
||||
|
||||
session.visit '/'
|
||||
|
||||
session.driver.trigger :click, '//div[@id=foo]//a'
|
||||
session.driver.trigger :mouseover, '#foo a.bar' # will be ignored by drivers who do not support it
|
||||
|
||||
nodelist = session.find 'li#foo a'
|
||||
nodelist.empty?
|
||||
nodelist.first.tag_name # => 'a'
|
||||
nodelist.first.text # => 'a cute link'
|
||||
nodelist.first.html # => 'a <em>cute</em> link'
|
||||
nodelist.first.attributes # => { :href => '/blah' }
|
||||
nodelist.first.trigger :click
|
||||
|
||||
session.request.url # => '/blah'
|
||||
session.response.ok? # => true
|
||||
|
||||
# fancy stuff, just builds on the stuff above!
|
||||
|
||||
session.click_link 'a cute link'
|
||||
session.click_button 'an awesome button'
|
||||
session.within '#foo' do
|
||||
click_link 'a cute link'
|
||||
end
|
||||
session.fill_in 'foo', :with => 'bar'
|
||||
session.choose 'Monkey'
|
||||
session.check 'I am awesome'
|
||||
session.wait_for '#fooo"
|
||||
|
||||
# In cuke:
|
||||
|
||||
When 'I am awesome' do
|
||||
page.check 'I am awesome'
|
||||
page.click_button 'FooBar'
|
||||
end
|
37
lib/webcat.rb
Normal file
37
lib/webcat.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module Webcat
|
||||
class << self
|
||||
attr_accessor :debug
|
||||
|
||||
def log(message)
|
||||
puts message if debug
|
||||
end
|
||||
end
|
||||
|
||||
class Session
|
||||
attr_reader :mode, :app
|
||||
|
||||
def initialize(mode, app)
|
||||
@mode = mode
|
||||
@app = app
|
||||
end
|
||||
|
||||
def driver
|
||||
@driver ||= Webcat::Driver::RackTest.new(app)
|
||||
end
|
||||
|
||||
def get(path)
|
||||
driver.get(path)
|
||||
end
|
||||
|
||||
def body
|
||||
driver.response.body
|
||||
end
|
||||
end
|
||||
|
||||
autoload :Server, 'webcat/server'
|
||||
|
||||
module Driver
|
||||
autoload :RackTest, 'webcat/rack_test_driver'
|
||||
autoload :Culerity, 'webcat/culerity_driver'
|
||||
end
|
||||
end
|
50
lib/webcat/culerity_driver.rb
Normal file
50
lib/webcat/culerity_driver.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require 'culerity'
|
||||
require 'rack'
|
||||
require 'net/http'
|
||||
|
||||
class Webcat::Driver::Culerity
|
||||
Response = Struct.new(:body)
|
||||
|
||||
attr_reader :app, :rack_server
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@rack_server = Webcat::Server.new(@app)
|
||||
@rack_server.boot
|
||||
end
|
||||
|
||||
def get(path)
|
||||
browser.goto(url(path))
|
||||
end
|
||||
|
||||
def body
|
||||
browser.text
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def url(path)
|
||||
rack_server.url(path)
|
||||
end
|
||||
|
||||
def server
|
||||
unless @_server
|
||||
@_server = ::Culerity::run_server
|
||||
at_exit do
|
||||
@_server.close
|
||||
end
|
||||
end
|
||||
@_server
|
||||
end
|
||||
|
||||
def browser
|
||||
unless @_browser
|
||||
@_browser = ::Culerity::RemoteBrowserProxy.new server, {:browser => :firefox, :log_level => :off}
|
||||
at_exit do
|
||||
@_browser.exit
|
||||
end
|
||||
end
|
||||
@_browser
|
||||
end
|
||||
|
||||
end
|
17
lib/webcat/rack_test_driver.rb
Normal file
17
lib/webcat/rack_test_driver.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'rack/test'
|
||||
|
||||
class Webcat::Driver::RackTest
|
||||
include ::Rack::Test::Methods
|
||||
attr_reader :app
|
||||
|
||||
alias_method :response, :last_response
|
||||
alias_method :request, :last_request
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def body
|
||||
response.body
|
||||
end
|
||||
end
|
48
lib/webcat/server.rb
Normal file
48
lib/webcat/server.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
class Webcat::Server
|
||||
attr_reader :app
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def port
|
||||
9081
|
||||
end
|
||||
|
||||
def host
|
||||
'localhost'
|
||||
end
|
||||
|
||||
def url(path)
|
||||
"http://#{host}:#{port}#{path}"
|
||||
end
|
||||
|
||||
def boot
|
||||
Webcat.log "[webcat] Booting Rack applicartion on port #{port}"
|
||||
start_time = Time.now
|
||||
Thread.new do
|
||||
Rack::Handler::Mongrel.run @app, :Port => port
|
||||
end
|
||||
Webcat.log "[webcat] checking if application has booted"
|
||||
loop do
|
||||
begin
|
||||
res = Net::HTTP.start(host, port) { |http| http.get('/') }
|
||||
|
||||
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
||||
Webcat.log "[webcat] application has booted"
|
||||
break
|
||||
end
|
||||
rescue Errno::ECONNREFUSED
|
||||
end
|
||||
|
||||
if Time.now - start_time > 5
|
||||
puts "[webcat] Rack application timed out during boot"
|
||||
exit
|
||||
end
|
||||
|
||||
Webcat.log '.'
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
10
script/console
Executable file
10
script/console
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env ruby
|
||||
# File: script/console
|
||||
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
||||
|
||||
libs = " -r irb/completion"
|
||||
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
||||
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
||||
libs << " -r #{File.dirname(__FILE__) + '/../lib/webcat.rb'}"
|
||||
puts "Loading webcat gem"
|
||||
exec "#{irb} #{libs} --simple-prompt"
|
14
script/destroy
Executable file
14
script/destroy
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env ruby
|
||||
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
begin
|
||||
require 'rubigen'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
require 'rubigen'
|
||||
end
|
||||
require 'rubigen/scripts/destroy'
|
||||
|
||||
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
||||
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
||||
RubiGen::Scripts::Destroy.new.run(ARGV)
|
14
script/generate
Executable file
14
script/generate
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env ruby
|
||||
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
begin
|
||||
require 'rubigen'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
require 'rubigen'
|
||||
end
|
||||
require 'rubigen/scripts/generate'
|
||||
|
||||
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
||||
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
||||
RubiGen::Scripts::Generate.new.run(ARGV)
|
10
spec/culerity_driver_spec.rb
Normal file
10
spec/culerity_driver_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
||||
require 'drivers_spec'
|
||||
|
||||
describe Webcat::Driver::Culerity do
|
||||
before do
|
||||
@driver = Webcat::Driver::Culerity.new(TestApp)
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
end
|
14
spec/drivers_spec.rb
Normal file
14
spec/drivers_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
||||
|
||||
shared_examples_for 'driver' do
|
||||
|
||||
describe '#get' do
|
||||
it "should fetch a response" do
|
||||
@driver.get('/')
|
||||
@driver.body.should == 'Hello world!'
|
||||
@driver.get('/foo')
|
||||
@driver.body.should == 'Another World'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
10
spec/rack_test_driver_spec.rb
Normal file
10
spec/rack_test_driver_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
||||
require 'drivers_spec'
|
||||
|
||||
describe Webcat::Driver::RackTest do
|
||||
before do
|
||||
@driver = Webcat::Driver::RackTest.new(TestApp)
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
end
|
16
spec/spec_helper.rb
Normal file
16
spec/spec_helper.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
$:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
|
||||
|
||||
require 'rubygems'
|
||||
require 'webcat'
|
||||
require 'sinatra/base'
|
||||
require 'rack'
|
||||
|
||||
class TestApp < Sinatra::Base
|
||||
get '/' do
|
||||
'Hello world!'
|
||||
end
|
||||
|
||||
get '/foo' do
|
||||
'Another World'
|
||||
end
|
||||
end
|
35
spec/webcat_spec.rb
Normal file
35
spec/webcat_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Session do
|
||||
before do
|
||||
@session = Webcat::Session.new(:rack_test, TestApp)
|
||||
end
|
||||
|
||||
describe '#driver' do
|
||||
it "should be a rack test driver" do
|
||||
@session.driver.should be_an_instance_of(Webcat::Driver::RackTest)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#app' do
|
||||
it "should remember the application" do
|
||||
@session.app.should == TestApp
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mode' do
|
||||
it "should remember the mode" do
|
||||
@session.mode.should == :rack_test
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get' do
|
||||
it "should fetch a response from the driver" do
|
||||
@session.get('/')
|
||||
@session.body.should == 'Hello world!'
|
||||
@session.get('/foo')
|
||||
@session.body.should == 'Another World'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
3
test/test_helper.rb
Normal file
3
test/test_helper.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
require 'stringio'
|
||||
require 'test/unit'
|
||||
require File.dirname(__FILE__) + '/../lib/webcat'
|
11
test/test_webcat.rb
Normal file
11
test/test_webcat.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require File.dirname(__FILE__) + '/test_helper.rb'
|
||||
|
||||
class TestWebcat < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_truth
|
||||
assert true
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue