Class: RspecSequel::Matchers::HaveColumnMatcher
- Defined in:
- lib/rspec_sequel/matchers/have_column.rb
Instance Method Summary collapse
Methods inherited from Base
#failure_message, #hash_to_nice_string, #initialize, #matches?, #negative_failure_message
Constructor Details
This class inherits a constructor from RspecSequel::Base
Instance Method Details
#description ⇒ Object
5 6 7 8 9 |
# File 'lib/rspec_sequel/matchers/have_column.rb', line 5 def description desc = "have a column #{@attribute.inspect}" desc << " with type #{@options[:type]}" if @options[:type] desc end |
#valid?(db, i, c, attribute, options) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rspec_sequel/matchers/have_column.rb', line 11 def valid?(db, i, c, attribute, ) # check column existance col = db.schema(c.table_name).detect{|col| col[0]==attribute} matching = !col.nil? # check type if @options[:type] expected = db.send(:type_literal, {:type => [:type]}).to_s if matching found = [col[1][:type].to_s, col[1][:db_type].to_s] @suffix << "(type found: #{found.uniq.join(", ")})" matching &&= found.include?(expected) end end matching end |