Class: RSpec::RubyContentMatchers::LicenseFile::HaveLicenseFile

Inherits:
Object
  • Object
show all
Includes:
RailsAssist::Artifact::Directory, RailsAssist::Directory
Defined in:
lib/cancan-permits/rspec/matchers/have_license_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ HaveLicenseFile

Returns a new instance of HaveLicenseFile.



11
12
13
# File 'lib/cancan-permits/rspec/matchers/have_license_file.rb', line 11

def initialize name
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/cancan-permits/rspec/matchers/have_license_file.rb', line 9

def name
  @name
end

Instance Method Details

#failure_messageObject



30
31
32
# File 'lib/cancan-permits/rspec/matchers/have_license_file.rb', line 30

def failure_message
  "No license file found for #{name} in #{license_dir} as expected"
end

#license_dirObject



15
16
17
# File 'lib/cancan-permits/rspec/matchers/have_license_file.rb', line 15

def license_dir
  File.join(app_dir, 'licenses')
end

#license_file(name) ⇒ Object



19
20
21
# File 'lib/cancan-permits/rspec/matchers/have_license_file.rb', line 19

def license_file name
  File.join(license_dir, "#{name}_license.rb")
end

#matches?(obj) {|File.read(file_name)| ... } ⇒ Boolean

Yields:

  • (File.read(file_name))

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/cancan-permits/rspec/matchers/have_license_file.rb', line 23

def matches? obj, &block
  file_name = license_file(name)
  found = File.file? file_name
  yield File.read(file_name) if block && found
  found
end

#negative_failure_messageObject



34
35
36
# File 'lib/cancan-permits/rspec/matchers/have_license_file.rb', line 34

def negative_failure_message
  "License file #{name} found in #{license_dir} but was not expected"
end