Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 0745b1ee1c94bcd89fd7c684bd13be5bb5093c53 @jferris jferris committed Feb 19, 2011
@@ -0,0 +1,12 @@
+*.swp
+bin
+*.swo
+*~
+*.o
+*.moc
+Makefile*
+qrc_*
+*.xcodeproj
+*.app
+moc_*.cpp
+.bundle
@@ -0,0 +1,5 @@
+source "http://rubygems.org"
+gem "rake"
+gem "rspec", :require => false
+gem "capybara"
+
@@ -0,0 +1,50 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ capybara (0.4.1.2)
+ celerity (>= 0.7.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.3)
+ celerity (0.8.8)
+ childprocess (0.1.7)
+ ffi (~> 0.6.3)
+ culerity (0.2.15)
+ diff-lcs (1.1.2)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
+ json_pure (1.5.1)
+ mime-types (1.16)
+ nokogiri (1.4.4)
+ rack (1.2.1)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rake (0.8.7)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.1)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.1.3)
+ childprocess (~> 0.1.5)
+ ffi (~> 0.6.3)
+ json_pure
+ rubyzip
+ xpath (0.1.3)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara
+ rake
+ rspec
@@ -0,0 +1,61 @@
+require 'rubygems'
+require 'bundler/setup'
+require 'fileutils'
+require 'rspec/core/rake_task'
+
+desc "Generate a new command called NAME"
+task :generate_command do
+ name = ENV['NAME'] or raise "Provide a name with NAME="
+
+ header = "src/#{name}.h"
+ source = "src/#{name}.cpp"
+
+ %w(h cpp).each do |extension|
+ File.open("templates/Command.#{extension}", "r") do |source_file|
+ contents = source_file.read
+ contents.gsub!("NAME", name)
+ File.open("src/#{name}.#{extension}", "w") do |target_file|
+ target_file.write(contents)
+ end
+ end
+ end
+
+ Dir.glob("src/*.pro").each do |project_file_name|
+ project = IO.read(project_file_name)
+ project.gsub!(/(HEADERS = .*)/, "\\1 #{name}.h")
+ project.gsub!(/(SOURCES = .*)/, "\\1 #{name}.cpp")
+ File.open(project_file_name, "w") { |file| file.write(project) }
+ end
+end
+
+desc "Generate a Makefile using qmake"
+file 'Makefile' do
+ sh("qmake -spec macx-g++")
+end
+
+desc "Regenerate dependencies using qmake"
+task :qmake => 'Makefile' do
+ sh("make qmake")
+end
+
+desc "Build the webkit server"
+task :build => :qmake do
+ sh("make")
+
+ FileUtils.mkdir("bin") unless File.directory?("bin")
+
+ if File.exist?("src/webkit_server.app")
+ FileUtils.cp("src/webkit_server.app/Contents/MacOS/webkit_server", "bin")
+ else
+ FileUtils.cp("src/webkit_server", "bin")
+ end
+end
+
+RSpec::Core::RakeTask.new do |t|
+ t.pattern = "spec/*_spec.rb"
+ t.rspec_opts = "--format progress"
+end
+
+desc "Default: build and run all specs"
+task :default => [:build, :spec]
+
@@ -0,0 +1,7 @@
+require "capybara"
+require "capybara/driver/webkit"
+
+Capybara.register_driver :webkit do |app|
+ Capybara::Driver::Webkit.new(app)
+end
+
@@ -0,0 +1,79 @@
+require "capybara"
+require "capybara/driver/webkit/node"
+require "capybara/driver/webkit/browser"
+
+class Capybara::Driver::Webkit
+ def initialize(app, options={})
+ @app = app
+ @options = options
+ @rack_server = Capybara::Server.new(@app)
+ @rack_server.boot if Capybara.run_server
+ @browser = Browser.new
+ end
+
+ def current_url
+ raise NotImplementedError
+ end
+
+ def visit(path)
+ @browser.visit(url(path))
+ end
+
+ def find(query)
+ @browser.find(query).map { |native| Node.new(self, native) }
+ end
+
+ def source
+ raise NotImplementedError
+ end
+
+ def body
+ raise NotImplementedError
+ end
+
+ def execute_script(script)
+ raise Capybara::NotSupportedByDriverError
+ end
+
+ def evaluate_script(script)
+ raise Capybara::NotSupportedByDriverError
+ end
+
+ def response_headers
+ raise Capybara::NotSupportedByDriverError
+ end
+
+ def status_code
+ raise Capybara::NotSupportedByDriverError
+ end
+
+ def within_frame(frame_id)
+ raise Capybara::NotSupportedByDriverError
+ end
+
+ def within_window(handle)
+ raise Capybara::NotSupportedByDriverError
+ end
+
+ def wait?
+ false
+ end
+
+ def wait_until(*args)
+ end
+
+ def reset!
+ @browser.reset!
+ end
+
+ def has_shortcircuit_timeout?
+ false
+ end
+
+ private
+
+ def url(path)
+ @rack_server.url(path)
+ end
+end
+
@@ -0,0 +1,64 @@
+require 'socket'
+
+class Capybara::Driver::Webkit
+ class Browser
+ def initialize
+ start_server
+ connect
+ end
+
+ def visit(url)
+ command "visit", url
+ end
+
+ def find(query)
+ command("find", query).split(",")
+ end
+
+ def reset!
+ command("reset")
+ end
+
+ private
+
+ def start_server
+ @pid = fork { exec("webkit_server") }
+ at_exit { Process.kill("INT", @pid) }
+ end
+
+ def connect
+ puts ">> Connecting"
+ Capybara.timeout(5) do
+ attempt_connect
+ !@socket.nil?
+ end
+ puts ">> Connected"
+ end
+
+ def attempt_connect
+ @socket = TCPSocket.open("localhost", 9200)
+ rescue Errno::ECONNREFUSED
+ end
+
+ def check
+ result = @socket.gets.strip
+ puts ">> #{result}"
+ unless result == 'ok'
+ raise
+ end
+ end
+
+ def command(name, *args)
+ puts ">> Sending #{name}"
+ @socket.puts name
+ args.each { |arg| @socket.puts arg }
+ check
+ read_response
+ end
+
+ def read_response
+ response_length = @socket.gets.to_i
+ @socket.read(response_length)
+ end
+ end
+end
@@ -0,0 +1,52 @@
+class Capybara::Driver::Webkit
+ class Node < Capybara::Driver::Node
+ def text
+ raise NotImplementedError
+ end
+
+ def [](name)
+ raise NotImplementedError
+ end
+
+ def value
+ raise NotImplementedError
+ end
+
+ def set(value)
+ raise NotImplementedError
+ end
+
+ def select_option
+ raise NotImplementedError
+ end
+
+ def unselect_option
+ raise NotImplementedError
+ end
+
+ def click
+ raise NotImplementedError
+ end
+
+ def drag_to(element)
+ raise NotImplementedError
+ end
+
+ def tag_name
+ raise NotImplementedError
+ end
+
+ def visible?
+ raise NotImplementedError
+ end
+
+ def path
+ raise NotSupportedByDriverError
+ end
+
+ def trigger(event)
+ raise NotSupportedByDriverError
+ end
+ end
+end
+
@@ -0,0 +1,34 @@
+require 'spec_helper'
+require 'capybara/driver/webkit'
+
+describe Capybara::Driver::Webkit do
+ let(:hello_app) do
+ lambda do |env|
+ body = <<-HTML
+ <html><body>
+ <script type="text/javascript">
+ document.write("he" + "llo");
+ </script>
+ </body></html>
+ HTML
+ [200,
+ { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
+ [body]]
+ end
+ end
+
+ subject { Capybara::Driver::Webkit.new(hello_app) }
+ after { subject.reset! }
+
+ it "finds content after loading a URL" do
+ subject.visit("/hello")
+ subject.find("//*[contains(., 'hello')]").should_not be_empty
+ end
+
+ it "has an empty page after reseting" do
+ subject.visit("/")
+ subject.reset!
+ subject.find("//*[contains(., 'hello')]").should be_empty
+ end
+end
+
@@ -0,0 +1,10 @@
+require 'rspec'
+require 'rspec/autorun'
+
+PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
+
+$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
+ENV["PATH"] = ENV["PATH"] + ":" + File.join(PROJECT_ROOT, "bin")
+
+Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) }
+
Oops, something went wrong.

0 comments on commit 0745b1e

Please sign in to comment.