lib/bbq/rspec.rb in bbq-0.0.4 vs lib/bbq/rspec.rb in bbq-0.1.0
- old
+ new
@@ -1,7 +1,8 @@
+require 'bbq'
+require 'bbq/session'
require 'rspec/core'
-require 'bbq/test_user'
require 'capybara/rspec/matchers'
module Bbq
module RSpecFeature
def self.included(base)
@@ -11,66 +12,68 @@
end
end
end
module RSpecMatchers
- class TestUserEyes
- def initialize(negative, *args)
- @args, @negative = args, negative
- end
+ extend RSpec::Matchers::DSL
- def matches?(actual)
- @negative ? actual.not_see?(*@args) : actual.see?(*@args)
+ matcher :see do |text|
+ chain :within do |locator|
+ @locator = locator
end
- def failure_message_for_should
- "expected to #{@negative ? negative_description : positive_description}"
+ match_for_should do |page|
+ if @locator
+ page.within(@locator) do
+ page.see? text
+ end
+ else
+ page.see? text
+ end
end
- def failure_message_for_should_not
- "expected to #{@negative ? positive_description : negative_description}"
+ match_for_should_not do |page|
+ if @locator
+ page.within(@locator) do
+ page.not_see? text
+ end
+ else
+ page.not_see? text
+ end
end
- def description
- @negative ? negative_description : positive_description
+ failure_message_for_should do |page|
+ body = if @locator
+ page.find(@locator).text
+ else
+ page.body
+ end
+ "expected to see #{text} in #{body}"
end
- protected
-
- def negative_description
- "not see any of the following: #{@args.join(', ')}"
+ 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
-
- def positive_description
- "see all of the following: #{@args.join(', ')}"
- end
end
-
- def see(*args)
- TestUserEyes.new(false, *args)
- end
-
- def not_see(*args)
- TestUserEyes.new(true, *args)
- end
end
class TestUser
include RSpec::Matchers
include Capybara::RSpecMatchers
include Bbq::RSpecMatchers
def see!(*args)
- args.each do |arg|
- page.should have_content(arg)
- end
+ see?(*args).should be_true
end
def not_see!(*args)
- args.each do |arg|
- page.should have_no_content(arg)
- end
+ not_see?(*args).should be_true
end
end
end
def self.feature(*args, &block)
@@ -85,6 +88,10 @@
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