Sha256: 551aacc52a39df4df6d3c2c7a2e74790023ba4090461e214127583747ff3be26

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

require File.join(File.dirname(__FILE__),'..','spec_helper')

describe Scaffolder::BinaryHelper do

  before(:each) do
    @help_tool = Scaffolder::Tool::Help

    @tool_class = Class.new(Scaffolder::Tool)
    @tool_name = 'type'
    Scaffolder::Tool.const_set(@tool_name.capitalize,@tool_class)

    @args = OpenStruct.new({ :rest => %W|#{@tool_name} arg1 arg2| })
  end

  after(:each) do
    Scaffolder::Tool.send(:remove_const,'Type')
  end

  subject do
    object = Object.new
    object.extend described_class
    object
  end

  describe "select_tool method" do

    it "should return corresponding tool subclass when requested by name" do
      subject[@tool_name].should == @tool_class
    end

    it "should return the help tool when passed an unknown name" do
      subject['unknown-tool'].should == @help_tool
    end

    it "should return the help tool when passed nil" do
      subject[nil].should == @help_tool
    end

  end

  it "should fetch the right tool class when requested" do
    tool, args = subject.determine_tool(@args)
    tool.should == @tool_class
    args.rest.should == @args.rest[-2..-1]
  end

  it "should fetch the help tool class when no arguments passed" do
    no_args = Hash.new
    no_args.expects(:rest).returns([])

    expected = no_args.clone
    expected[:empty_args] = true

    tool, args = subject.determine_tool(no_args)

    tool.should == @help_tool
    args.should == expected
  end

  it "should fetch the help tool class when an invalid argument is passed" do
    args = Hash.new
    args.expects(:rest).returns(['unknown-tool'])
    updated_args = args.clone
    updated_args[:unknown_tool] = 'unknown-tool'

    tool, args = subject.determine_tool(args)

    tool.should == @help_tool
    args.should == updated_args
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scaffolder-tools-0.1.2 spec/scaffolder/binary_helper_spec.rb
scaffolder-tools-0.1.1 spec/scaffolder/binary_helper_spec.rb
scaffolder-tools-0.1.0 spec/scaffolder/binary_helper_spec.rb