Skip to content

Commit

Permalink
Exorcise poltergeist
Browse files Browse the repository at this point in the history
  • Loading branch information
haines committed Nov 16, 2012
1 parent 21418f1 commit 067ecd3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions ci/install_phantomjs

This file was deleted.

1 change: 0 additions & 1 deletion draper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 5 additions & 11 deletions spec/integration/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,20 @@
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
Expand Down
17 changes: 9 additions & 8 deletions spec/support/dummy_app.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -66,7 +67,7 @@ def localhost
def port
@port ||= begin
server = TCPServer.new(localhost, 0)
port = server.addr[1]
server.addr[1]
ensure
server.close if server
end
Expand Down
10 changes: 8 additions & 2 deletions spec/support/matchers/have_text.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'capybara'

module HaveTextMatcher
def have_text(text)
HaveText.new(text)
Expand All @@ -14,7 +16,7 @@ def in(css)
end

def matches?(subject)
@subject = subject
@subject = Capybara.string(subject)

@subject.has_css?(@css || "*", text: @text)
end
Expand All @@ -30,7 +32,11 @@ def failure_message_for_should_not
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
Expand Down

0 comments on commit 067ecd3

Please sign in to comment.