Module: Cog::SpecHelpers

Extended by:
SpecHelpers
Included in:
SpecHelpers
Defined in:
lib/cog/spec_helpers.rb,
lib/cog/spec_helpers/runner.rb,
lib/cog/spec_helpers/matchers.rb,
lib/cog/spec_helpers/matchers/match_maker.rb

Overview

Modules and classes to help write specs for testing cog

Requiring the helpers will make extra Matchers available to your RSpec tests. These are useful for testing a Invocation, which is returned from a call to Runner#run

Examples:

require 'cog/spec_helpers'

describe 'The command line interface' do

  include Cog::SpecHelpers

  before :all do
    @cog = Cog::SpecHelpers::Runner.new 'bin/cog'
  end

  it 'should print help when no args are passed' do
    expect(@cog.run).to show_help
  end

  context 'in an uninitialized project' do

    before :each do
      use_fixture :uninitialized
    end

    it 'running `cog init` should make a Cogfile' do
      expect(@cog.run(:init)).to make(cogfile_path)
    end

  end
end

Defined Under Namespace

Modules: Matchers Classes: Invocation, Runner

Instance Method Summary collapse

Instance Method Details

#active_fixture_dirString

Returns directory of the active fixture.

Returns:

  • (String)

    directory of the active fixture.



47
48
49
# File 'lib/cog/spec_helpers.rb', line 47

def active_fixture_dir
  File.join spec_root, 'active_fixture'
end

#active_home_fixture_dirString

Returns directory of the active home fixture.

Returns:

  • (String)

    directory of the active home fixture.



52
53
54
# File 'lib/cog/spec_helpers.rb', line 52

def active_home_fixture_dir
  File.join spec_root, 'active_home_fixture'
end

#cog_directoryString

Returns path to the cog directory in the active spec fixture.

Returns:

  • (String)

    path to the cog directory in the active spec fixture



62
63
64
# File 'lib/cog/spec_helpers.rb', line 62

def cog_directory
  File.join active_fixture_dir, 'cog'
end

#cogfile_pathString

Returns path to the Cogfile in the active spec fixture.

Returns:

  • (String)

    path to the Cogfile in the active spec fixture



57
58
59
# File 'lib/cog/spec_helpers.rb', line 57

def cogfile_path
  File.join active_fixture_dir, 'Cogfile'
end

#generated_file(filename) ⇒ String

Returns absolute path to the generated file.

Parameters:

  • filename (String)

    name of a generated source file

Returns:

  • (String)

    absolute path to the generated file



86
87
88
# File 'lib/cog/spec_helpers.rb', line 86

def generated_file(filename)
  File.expand_path File.join(active_fixture_dir, 'src', filename)
end

#generator(name) ⇒ String

Returns path to the generator with the given name.

Parameters:

  • name (String)

    active fixture generator identifier

Returns:

  • (String)

    path to the generator with the given name



68
69
70
# File 'lib/cog/spec_helpers.rb', line 68

def generator(name)
  File.expand_path File.join(active_fixture_dir, 'cog', 'generators', "#{name}.rb")
end

#plugin(name) ⇒ String

Returns absolute file system path to the plugin directory.

Parameters:

  • name (String)

    plugin name

Returns:

  • (String)

    absolute file system path to the plugin directory



80
81
82
# File 'lib/cog/spec_helpers.rb', line 80

def plugin(name)
  File.expand_path File.join(active_fixture_dir, 'cog', 'plugins', name.to_s)
end

#spec_rootString

Returns absolute path to the root spec directory.

Returns:

  • (String)

    absolute path to the root spec directory



42
43
44
# File 'lib/cog/spec_helpers.rb', line 42

def spec_root
  File.expand_path File.join(File.dirname(__FILE__), '..', '..', 'spec')
end

#template(name) ⇒ String

Returns absolute file system path to the template.

Parameters:

  • name (String)

    template identifier (without the .erb extension)

Returns:

  • (String)

    absolute file system path to the template



74
75
76
# File 'lib/cog/spec_helpers.rb', line 74

def template(name)
  File.expand_path File.join(active_fixture_dir, 'cog', 'templates', name.to_s)
end

#use_fixture(name) ⇒ nil

The next cog spec will execute in a fresh copy of the given fixture Fixture directories are stored in spec/fixtures.

Parameters:

  • name (String)

    name of the fixture

Returns:

  • (nil)


94
95
96
97
98
99
# File 'lib/cog/spec_helpers.rb', line 94

def use_fixture(name)
  path = File.join spec_root, 'fixtures', name.to_s
  copy_fixture path, active_fixture_dir
  Dir.chdir active_fixture_dir
  nil
end

#use_home_fixture(name) ⇒ nil

The next cog spec will execute in a fresh copy of the given home fixture Home fixture directories are stored in spec/home_fixtures

Parameters:

  • name (String)

    name of the home fixture

Returns:

  • (nil)


105
106
107
108
109
# File 'lib/cog/spec_helpers.rb', line 105

def use_home_fixture(name)
  path = File.join spec_root, 'home_fixtures', name.to_s
  copy_fixture path, active_home_fixture_dir
  nil
end