Skip to content

Commit

Permalink
Merge 50c4854 into 762f3f3
Browse files Browse the repository at this point in the history
  • Loading branch information
josepjaume committed Jan 25, 2014
2 parents 762f3f3 + 50c4854 commit 4bae00c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -2,3 +2,7 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- rbx-19mode
- rbx

cache: bundler
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -10,7 +10,7 @@ group :test do
gem 'guard'
gem 'guard-minitest'
gem 'guard-spinach'
gem 'capybara', '~> 2.0.0'
gem 'capybara'
gem "rspec"
gem 'fakefs'
end
Expand Down
64 changes: 32 additions & 32 deletions lib/spinach/capybara.rb
Expand Up @@ -17,43 +17,43 @@ class FeatureSteps
# end
#
module Capybara
# Enhances a FeatureSteps with Capybara goodness.
#
# @param [Class] base
# The host class.
#
# @api public
def self.included(base)
base.class_eval do
include ::Capybara::DSL
if defined?(RSpec)
require 'rspec/matchers'
require 'capybara/rspec'
include ::Capybara::RSpecMatchers
end
class CapybaraDslDelegator
include ::Capybara::DSL
if defined?(RSpec)
require 'rspec/matchers'
require 'capybara/rspec'
include ::Capybara::RSpecMatchers
end
end

def visit(*args)
stream = STDOUT
old_stream = stream.dup
stream.reopen(null_device)
stream.sync = true
super
ensure
stream.reopen(old_stream)
end
def visit(*args)
stream = STDOUT
old_stream = stream.dup
stream.reopen(null_device)
stream.sync = true
instance.visit *args
ensure
stream.reopen(old_stream)
end

def null_device
return @null_device if defined?(@null_device)
def instance
@instance ||= CapybaraDslDelegator.new
end

if RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
@null_device = "NUL"
else
@null_device = "/dev/null"
end
def method_missing(m, *args)
instance.send m, *args
end

def null_device
return @null_device if defined?(@null_device)

@null_device
end
if RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
@null_device = "NUL"
else
@null_device = "/dev/null"
end

@null_device
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion spinach.gemspec
Expand Up @@ -12,10 +12,12 @@ Gem::Specification.new do |gem|

gem.add_runtime_dependency 'gherkin-ruby', '>= 0.3.1'
gem.add_runtime_dependency 'colorize', '0.5.8'
gem.add_runtime_dependency 'json'
gem.add_runtime_dependency 'rubysl' if RUBY_ENGINE == 'rbx'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'mocha'
gem.add_development_dependency 'sinatra'
gem.add_development_dependency 'capybara', '~> 2.0.0'
gem.add_development_dependency 'capybara'
gem.add_development_dependency 'pry'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'rspec'
Expand Down
30 changes: 20 additions & 10 deletions test/spinach/capybara_test.rb
Expand Up @@ -5,16 +5,18 @@
require 'spinach/capybara'
require 'sinatra/base'

class SinatraStubApp < Sinatra::Base
get '/' do
'Hello world!'
describe Spinach::FeatureSteps::Capybara do
let(:sinatra_class) do
Class.new(Sinatra::Base) do
get '/' do
'Hello world!'
end
end
end
end

describe Spinach::FeatureSteps::Capybara do
before do
Capybara.current_driver = :rack_test
Capybara.app = SinatraStubApp
Capybara.app = sinatra_class

class TestFeature < Spinach::FeatureSteps
include Spinach::FeatureSteps::Capybara
Expand Down Expand Up @@ -46,18 +48,26 @@ def go_home
Scenario: Another test scenario
Given Hello
Then Goodbye
""").parse
""").parse
}

let(:failing_feature) { Spinach::Parser.new("""
Feature: A test feature
Scenario: A test scenario
Given Fail
""").parse
""").parse
}

it 'includes capybara into all features' do
@feature.kind_of?(Capybara::DSL).must_equal true
it 'responds to Capybara::DSL methods' do
@feature.respond_to?(:page).must_equal false
end

it 'does not respond to non Capybara::DSL methods' do
@feature.respond_to?(:strange).must_equal false
end

it 'raises NoMethodError when calling a non Capybara::DSL methods' do
proc { @feature.strange }.must_raise(NoMethodError)
end

it 'goes to a capybara page and returns its result' do
Expand Down
6 changes: 5 additions & 1 deletion test/spinach/reporter/stdout/error_reporting_test.rb
Expand Up @@ -3,7 +3,11 @@
require_relative '../../../test_helper'

describe Spinach::Reporter::Stdout do
let(:exception) { StandardError.new('Something went wrong') }
let(:exception) do
mock "exception" do
stubs(:message).returns "Something went wrong"
end
end

let(:error) do
[stub(name: 'My feature'),
Expand Down
2 changes: 0 additions & 2 deletions test/spinach/reporter/stdout_test.rb
Expand Up @@ -48,8 +48,6 @@

describe '#after_scenario_run' do
describe 'in case of error' do
let(:exception) { anything }

before do
@reporter.scenario_error = exception
end
Expand Down

0 comments on commit 4bae00c

Please sign in to comment.