Sha256: 230c68c518437acbabd07dd2e86bcf5162251111f70a3898b3946e4b8eacc9f9
Contents?: true
Size: 1.52 KB
Versions: 4
Compression:
Stored size: 1.52 KB
Contents
require 'rspec/expectations' module TubeHelper def self.extended(klass) klass.instance_eval do chain :for do |tube_name| self.tube_name = tube_name end end end private attr_accessor :tube_name def tubes(beanstalk) beanstalk.instance_variable_get(:@connections)['default'].instance_variable_get(:@tubes) end def tube_name @tube_name || 'default' end def tube_size(beanstalk) states = tubes(beanstalk)[tube_name] || {} (states['ready'] || []).size end end RSpec::Matchers.define :have_tube_size_of do |size| extend TubeHelper match do |actual| tube_size(actual) == size end failure_message_for_should do |actual| "expected that tube #{actual} would have #{size} jobs, but got #{tube_size(actual)} jobs instead" end failure_message_for_should_not do |actual| "expected that tube #{actual} would not have #{size} jobs, but got #{tube_size(actual)} jobs instead" end description do "have #{size} jobs in tube" end end RSpec::Matchers.define :have_tube_size_of_gt do |size| extend TubeHelper match do |actual| tube_size(actual) > size end failure_message_for_should do |actual| "expected that tube #{actual} would have greater than #{size} jobs, but got #{tube_size(actual)} jobs instead" end failure_message_for_should_not do |actual| "expected that tube #{actual} would not have greater than #{size} jobs, but got #{tube_size(actual)} jobs instead" end description do "have greater than #{size} jobs in tube" end end
Version data entries
4 entries across 4 versions & 1 rubygems