Class: Array

Inherits:
Object show all
Defined in:
lib/spectre/helpers.rb,
lib/spectre/assertion.rb

Instance Method Summary collapse

Instance Method Details

#first_elementObject



122
123
124
# File 'lib/spectre/helpers.rb', line 122

def first_element
  self[0]
end

#last_elementObject



126
127
128
# File 'lib/spectre/helpers.rb', line 126

def last_element
  self[-1]
end

#should_be_emptyObject

Raises:

  • (AssertionFailure)


120
121
122
# File 'lib/spectre/assertion.rb', line 120

def should_be_empty
  raise AssertionFailure.new('List is not empty', self) unless self.empty?
end

#should_contain(val) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/spectre/assertion.rb', line 96

def should_contain(val)
  list = self

  if val.is_a? Hash and self.all? { |x| x.is_a? OpenStruct or x.is_a? Hash }
    list = self.map { |x| OpenStruct.new(x) }
    val = OpenStruct.new(val)
  end

  evaluate(val, "#{list} should contain #{val.to_s}") do |x|
    list.include? x
  end
end

#should_not_be_emptyObject

Raises:

  • (AssertionFailure)


124
125
126
# File 'lib/spectre/assertion.rb', line 124

def should_not_be_empty
  raise AssertionFailure.new('List is empty', self) if self.empty?
end

#should_not_contain(val) ⇒ Object

Raises:

  • (AssertionFailure)


109
110
111
112
113
114
115
116
117
118
# File 'lib/spectre/assertion.rb', line 109

def should_not_contain(val)
  list = self

  if val.is_a? Hash and self.all? { |x| x.is_a? OpenStruct or x.is_a? Hash }
    list = self.map { |x| OpenStruct.new(x) }
    val = OpenStruct.new(val)
  end

  raise AssertionFailure.new("[#{list.join(', ').trim}] should not contain '#{val.to_s.trim}'", val, list) if list.include? val
end