Skip to content

Commit

Permalink
add helper comments and refactor transport test
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Quick <jquick@chef.io>
  • Loading branch information
jquick committed Nov 1, 2017
1 parent 42e6dff commit 0425afb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions lib/train/platforms/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def detect(&block)
@detect = block
self
elsif @detect.nil?
# we are returning a block that just returns false here
# to skip the family/platform evaluation if detect is not set
->(_) { false }
else
@detect
Expand Down
2 changes: 2 additions & 0 deletions lib/train/platforms/detect/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def scan
# start with the platform/families who have no families (the top levels)
top = Train::Platforms.top_platforms
top.each do |_name, plat|
# we are doing a instance_eval here to make sure we have the proper
# context with all the detect helper methods
next unless instance_eval(&plat.detect) == true

# if we have a match start looking at the children
Expand Down
1 change: 0 additions & 1 deletion test/unit/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
require 'mocha/setup'

require 'train'
require 'train/platforms/detect'
24 changes: 13 additions & 11 deletions test/unit/transports/local_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
require 'helper'
require 'train/transports/local'

$transport = nil
describe 'local transport' do
let(:transport) do
if $transport.nil?
plat = Train::Platforms.name('mock').in_family('linux')
plat.add_platform_methods
Train::Platforms::Detect.stubs(:scan).returns(plat)
$transport = Train::Transports::Local.new
end
class TransportHelper
attr_accessor :transport

$transport
def initialize
Train::Platforms::Detect::Specifications::OS.load
plat = Train::Platforms.name('mock').in_family('linux')
plat.add_platform_methods
Train::Platforms::Detect.stubs(:scan).returns(plat)
@transport = Train::Transports::Local.new
end
end

describe 'local transport' do
let(:transport) { TransportHelper.new.transport }
let(:connection) { transport.connection }

it 'can be instantiated' do
Expand All @@ -26,7 +28,7 @@
end

it 'provides a uri' do
connection.uri.must_equal "local://"
connection.uri.must_equal 'local://'
end

it 'doesnt wait to be read' do
Expand Down
4 changes: 2 additions & 2 deletions test/unit/transports/ssh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
require 'train/transports/ssh'

describe 'ssh transport' do
let(:cls) {
let(:cls) do
plat = Train::Platforms.name('mock').in_family('linux')
plat.add_platform_methods
Train::Platforms::Detect.stubs(:scan).returns(plat)
Train::Transports::SSH
}
end
let(:conf) {{
host: rand.to_s,
password: rand.to_s,
Expand Down

0 comments on commit 0425afb

Please sign in to comment.