Class: Spex::ChangedModeCheck

Inherits:
FileCheck show all
Defined in:
lib/spex/checks/changed_mode_check.rb

Instance Attribute Summary

Attributes inherited from Check

#options, #target

Instance Method Summary collapse

Methods inherited from FileCheck

#kind, #kind_name

Methods inherited from Check

[], #active?, as, each, example, examples, #initialize, option, options, #prepare, registry, #validate!

Constructor Details

This class inherits a constructor from Spex::Check

Instance Method Details

#afterObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/spex/checks/changed_mode_check.rb', line 22

def after
  assert File.exist?(target), "File does not exist at #{target}"
  mode = current_mode.to_s(8)
  if options[:to]
    assert_equal options[:to].to_s(8), mode
  elsif active?
    assert_not_equal @before_mode.to_s(8), mode, "Mode is still #{@before_mode.to_s(8)}"
  elsif !active?
    assert_equal @before_mode.to_s(8), mode, "Mode was changed from #{@before_mode.to_s(8)} to #{mode}"
  end
end

#beforeObject



12
13
14
15
16
17
18
19
20
# File 'lib/spex/checks/changed_mode_check.rb', line 12

def before
  assert File.exist?(target), "File does not exist at #{target}"
  if options[:from]
    assert_equal options[:from].to_s(8), current_mode.to_s(8)
  elsif options[:to]
    assert_not_equal options[:to].to_s(8), current_mode.to_s(8), "Mode will not be changed; already at mode #{options[:to].to_s(8)}"
  end
  @before_mode = current_mode
end

#to_sObject



34
35
36
# File 'lib/spex/checks/changed_mode_check.rb', line 34

def to_s      
  [super, detail].join(' ')
end