Ravn::SpecHelpers::

BaseHelpers module

A collection of test helper functions and classes.

Constants

TEST_DATA_DIR

The directory to look in for fixture data

Public Class Methods

cleanup_tmpfiles()

Clean any files generated during a spec run.

# File lib/ravn/spec_helpers/base_helpers.rb, line 38
def self::cleanup_tmpfiles
        Pathname( Dir::Tmpname.tmpdir ).children.
                select{|f| f.basename.to_s.start_with?(/ravn.*\-test\-/) }.
                each( &:rmtree )
end
included( context )

Inclusion callback – install some hooks

# File lib/ravn/spec_helpers/base_helpers.rb, line 20
def self::included( context )
        context.before( :all ) do
                Loggability.logger.warn "Setting up a temporary device ID file."
                Ravn::SpecHelpers::BaseHelpers.setup_device_id
        end

        context.after( :each ) do
                Ravn::SpecHelpers::RecordingActor.instance = nil
        end

        context.after( :all ) do
                Ravn::SpecHelpers::BaseHelpers.cleanup_tmpfiles
        end

end

Public Instance Methods

have_a_line_matching( regexp )

RSpec matcher – set up the expectation that the lefthand side is Enumerable, and that at least one of the objects yielded while iterating matches regexp when converted to a String.

# File lib/ravn/spec_helpers/base_helpers.rb, line 89
def have_a_line_matching( regexp )
        return HaveALineMatching.new( regexp )
end
load_fixture_data( name )

Load data from the spec/data directory with the specified name, deserializing it if it’s YAML or JSON, and returning it.

# File lib/ravn/spec_helpers/base_helpers.rb, line 65
def load_fixture_data( name )
        name = name.to_s
        path = TEST_DATA_DIR + name
        path = TEST_DATA_DIR + "#{name}.json" unless path.exist? || !File.extname(name).empty?
        path = TEST_DATA_DIR + "#{name}.yaml" unless path.exist? || !File.extname(name).empty?
        path = TEST_DATA_DIR + "#{name}.yml"  unless path.exist? || !File.extname(name).empty?
        path = TEST_DATA_DIR + "#{name}.txt"  unless path.exist? || !File.extname(name).empty?

        rawdata = path.read( encoding: 'utf-8' )

        return case path.extname
                when '.json'
                        Yajl::Parser.parse( rawdata )
                when '.yml', '.yaml'
                        Psych.safe_load( rawdata, symbolize_names: true )
                else
                        rawdata
                end
end
setup_device_id()

Set the pathname of the device ID file to a temporary file.

# File lib/ravn/spec_helpers/base_helpers.rb, line 56
def setup_device_id
        Ravn.device_id_file = tmpfile_pathname( 'device-id' )
        Loggability.logger.warn "Setting device ID file to %s" % [ Ravn.device_id_file ]
        Ravn.device_id
end
spawn_recording_actor( name_or_opts )

Spawn a RecordingActor and return its reference.

# File lib/ravn/spec_helpers/base_helpers.rb, line 95
def spawn_recording_actor( name_or_opts )
        return Ravn::SpecHelpers::RecordingActor.spawn!( name_or_opts )
end
tmpfile_pathname( filetype='spec' )

Return a Pathname pointing to a temporary file.

# File lib/ravn/spec_helpers/base_helpers.rb, line 50
def tmpfile_pathname( filetype='spec' )
        Pathname(Dir::Tmpname.create(['ravn-', '-test-' + filetype]) {})
end