Sha256: a90ea21468f0d16e618dcf62bbc47505ff94f65fdb4d7c022cd307eca8d016cd

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

require 'bbq'
require 'bbq/session'
require 'rspec/core'
require 'capybara/rspec/matchers'

module Bbq
  module RSpecFeature
    def self.included(base)
      base.instance_eval do
        alias :background :before
        alias :scenario :it
      end
    end
  end

  module RSpecMatchers
    extend RSpec::Matchers::DSL

    matcher :see do |text|
      chain :within do |locator|
        @locator = locator
      end

      match_for_should do |page|
        if @locator
          page.within(@locator) do
            page.see? text
          end
        else
          page.see? text
        end
      end

      match_for_should_not do |page|
        if @locator
          page.within(@locator) do
            page.not_see? text
          end
        else
          page.not_see? text
        end
      end

      failure_message_for_should do |page|
        body = if @locator
          page.find(@locator).text
        else
          page.body
        end
        "expected to see #{text} in #{body}"
      end

      failure_message_for_should_not do |page|
        body = if @locator
          page.find(@locator).text
        else
          page.body
        end
        "expected not to see #{text} in #{body}"
      end
    end
  end

  class TestUser
    include RSpec::Matchers
    include Capybara::RSpecMatchers
    include Bbq::RSpecMatchers

    def see!(*args)
      see?(*args).should be_true
    end

    def not_see!(*args)
      not_see?(*args).should be_true
    end
  end
end

def self.feature(*args, &block)
  options = if args.last.is_a?(Hash) then args.pop else {} end
  options[:type] = :acceptance
  options[:caller] ||= caller
  args.push(options)

  describe(*args, &block)
end

RSpec.configuration.include Bbq::RSpecFeature, :type => :acceptance

RSpec.configure do |config|
  config.include Capybara::RSpecMatchers, :type => :acceptance
  config.include Bbq::RSpecMatchers, :type => :acceptance

  config.after :each, :type => :acceptance do
    Bbq::Session.pool.release
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bbq-0.2.1 lib/bbq/rspec.rb
bbq-0.2.0 lib/bbq/rspec.rb
bbq-0.1.0 lib/bbq/rspec.rb