Class: RspecSequel::Base

Inherits:
Object
  • Object
show all
Includes:
RSpec::Mocks::ExampleMethods
Defined in:
lib/rspec_sequel/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute, options = {}) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/rspec_sequel/base.rb', line 11

def initialize(attribute, options={})
  raise ArgumentError, "not enough params for matcher, required attribute is missing" if attribute.nil?
  @attribute = attribute
  @options = options
  @description = []
end

Instance Method Details

#failure_messageObject



29
30
31
# File 'lib/rspec_sequel/base.rb', line 29

def failure_message
  [@prefix, description, @suffix].flatten.compact.join(" ")
end

#failure_message_when_negatedObject



33
34
35
# File 'lib/rspec_sequel/base.rb', line 33

def failure_message_when_negated
  [@prefix, "not", description, @suffix].flatten.compact.join(" ")
end

#hash_to_nice_string(hash) ⇒ Object



37
38
39
# File 'lib/rspec_sequel/base.rb', line 37

def hash_to_nice_string(hash)
  hash.sort{|a,b| a[0].to_s<=>b[0].to_s}.collect{|param| param.collect{|v| v.inspect}.join(" => ")}.join(", ")
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
# File 'lib/rspec_sequel/base.rb', line 18

def matches?(target)
  @suffix = []
  if target.is_a?(Sequel::Model)
    @prefix = "expected #{target.inspect} to"
    valid?(target.db, target, target.class, @attribute, @options)
  else
    @prefix = "expected #{target.table_name.to_s.classify} to"
    valid?(target.db, target.new, target, @attribute, @options)
  end
end