Exorcise poltergeist

This commit is contained in:
Andrew Haines 2012-11-16 10:34:10 +00:00
parent 21418f1890
commit 067ecd3153
6 changed files with 22 additions and 32 deletions

View File

@ -8,7 +8,3 @@ matrix:
allow_failures:
- rvm: rbx-19mode
- rvm: ruby-head
before_script:
- sudo ci/install_phantomjs
- "export PATH=phantomjs/bin:$PATH"
- phantomjs --version

View File

@ -1,6 +0,0 @@
#!/bin/bash
version=phantomjs-1.7.0-linux-i686
wget http://phantomjs.googlecode.com/files/$version.tar.bz2
tar xjf $version.tar.bz2
mv $version phantomjs

View File

@ -26,5 +26,4 @@ Gem::Specification.new do |s|
s.add_development_dependency 'minitest-rails', '~> 0.2'
s.add_development_dependency 'minitest', '~> 3.0' if RUBY_PLATFORM == "java"
s.add_development_dependency 'capybara'
s.add_development_dependency 'poltergeist'
end

View File

@ -22,26 +22,20 @@ shared_examples_for "a decorator in a view" do
end
describe "integration" do
include Capybara::DSL
rails_env = ENV["RAILS_ENV"].to_s
raise ArgumentError, "RAILS_ENV must be development or production" unless ["development", "production"].include?(rails_env)
app = DummyApp.new(rails_env)
app = DummyApp.new(ENV["RAILS_ENV"])
app.start_server do
describe "in #{rails_env}" do
let(:environment) { rails_env }
before { Capybara.app_host = app.url }
describe "in #{app.environment}" do
let(:environment) { app.environment }
context "in a view" do
before { visit("/posts/1") }
let(:page) { app.get("/posts/1") }
it_behaves_like "a decorator in a view"
end
context "in a mailer" do
before { visit("/posts/1/mail") }
let(:page) { app.get("/posts/1/mail") }
it_behaves_like "a decorator in a view"
end

View File

@ -1,25 +1,26 @@
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
require 'singleton'
require 'socket'
require 'net/http'
# Adapted from code by Jon Leighton
# https://github.com/jonleighton/focused_controller/blob/ec7ccf1/test/acceptance/app_test.rb
Capybara.run_server = false
Capybara.default_driver = :poltergeist
class DummyApp
def initialize(environment)
raise ArgumentError, "Environment must be development or production" unless ["development", "production"].include?(environment.to_s)
@environment = environment
end
attr_reader :environment
def url
"http://#{localhost}:#{port}"
end
def get(path)
Net::HTTP.get(URI(url + path))
end
def within_app(&block)
Dir.chdir(root, &block)
end
@ -66,7 +67,7 @@ class DummyApp
def port
@port ||= begin
server = TCPServer.new(localhost, 0)
port = server.addr[1]
server.addr[1]
ensure
server.close if server
end

View File

@ -1,3 +1,5 @@
require 'capybara'
module HaveTextMatcher
def have_text(text)
HaveText.new(text)
@ -14,7 +16,7 @@ module HaveTextMatcher
end
def matches?(subject)
@subject = subject
@subject = Capybara.string(subject)
@subject.has_css?(@css || "*", text: @text)
end
@ -30,7 +32,11 @@ module HaveTextMatcher
private
def within
"#{inside} within\n#{@subject.html}"
if @css && @subject.has_css?(@css)
"within\n#{@subject.find(@css).native}"
else
"#{inside} within\n#{@subject.native}"
end
end
def inside