Skip to content

Commit

Permalink
WIP commands.run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lacostej committed Aug 23, 2017
1 parent 877f6d5 commit d4ec666
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 18 deletions.
7 changes: 5 additions & 2 deletions lib/u3d/commands.rb
Expand Up @@ -152,7 +152,8 @@ def run(options: {}, run_args: [])
version = options[:unity_version]

runner = Runner.new
pp = runner.find_projectpath_in_args(run_args)
args_pp = Runner.find_projectpath_in_args(run_args)
pp = args_pp
pp = Dir.pwd unless pp
up = UnityProject.new(pp)

Expand All @@ -167,7 +168,9 @@ def run(options: {}, run_args: [])

# we could
# * support matching 5.3.6p3 if passed 5.3.6
unity = Installer.create.installed.find { |u| u.version == version }
installed = Installer.create.installed
puts installed.class
unity = installed.find { |u| u.version == version }
UI.user_error! "Unity version '#{version}' not found" unless unity
runner.run(unity, run_args, raw_logs: options[:raw_logs])
end
Expand Down
28 changes: 15 additions & 13 deletions lib/u3d/unity_runner.rb
Expand Up @@ -77,22 +77,24 @@ def find_and_prepare_logfile(installation, args)
log_file
end

# rubocop:disable MethodName
def find_logFile_in_args(args)
# rubocop:enable MethodName
find_arg_in_args('-logFile', args)
end
class << self
# rubocop:disable MethodName
def find_logFile_in_args(args)
# rubocop:enable MethodName
find_arg_in_args('-logFile', args)
end

def find_projectpath_in_args(args)
find_arg_in_args('-projectpath', args)
end
def find_projectpath_in_args(args)
find_arg_in_args('-projectpath', args)
end

def find_arg_in_args(arg_to_find, args)
raise 'Only arguments of type array supported right now' unless args.is_a?(Array)
args.each_with_index do |arg, index|
return args[index + 1] if arg == arg_to_find && index < args.count - 1
def find_arg_in_args(arg_to_find, args)
raise 'Only arguments of type array supported right now' unless args.is_a?(Array)
args.each_with_index do |arg, index|
return args[index + 1] if arg == arg_to_find && index < args.count - 1
end
nil
end
nil
end

private
Expand Down
3 changes: 2 additions & 1 deletion spec/support/setups.rb
Expand Up @@ -61,9 +61,10 @@ def expect_no_install
expect(U3d::Installer).to_not receive(:install_modules)
end

def in_a_project(version)
def in_a_project(version: nil, path: nil)
project = double("UnityProject")
allow(U3d::UnityProject).to receive(:new) { project }
allow(project).to receive(:path) { path }
allow(project).to receive(:exist?) { true }
allow(project).to receive(:editor_version) { version }
end
Expand Down
64 changes: 62 additions & 2 deletions spec/u3d/commands_spec.rb
Expand Up @@ -227,7 +227,7 @@
# no version specified -> look for version in current project folder if any
describe 'when no version is specified' do
it 'fetches the version of the project in the current folder' do
in_a_project '1.2.3f4'
in_a_project(version: '1.2.3f4')
on_fake_os
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })

Expand Down Expand Up @@ -492,7 +492,7 @@
# no version specified -> look for version in current project folder if any
describe 'when no version is specified' do
it 'fetches the version of the project in the current folder' do
in_a_project '1.2.3f4'
in_a_project(version: '1.2.3f4')
on_fake_os
expect_privileges_check

Expand Down Expand Up @@ -768,5 +768,65 @@
# passes all lines through the log analyser with the configured (default) log rule
# QUESTION: EOL issue ? - what about logs from other platforms?
end

# ---
# RUN
# ---
describe "#run", focus: true do
context 'inside a given unity project' do
it "fails if it cannot find the project's version" do
are_installed([])
projectpath = 'fakepath'
in_a_project(version: '1.2.3f4', path: projectpath)

runner = double("Runner")
allow(U3d::Runner).to receive(:new) { runner }

expect do
U3d::Commands.run(
options: {},
run_args: []
)
end.to raise_error U3dCore::Interface::UIError
end

it "uses the project's unity version and path" do
unity = fake_installation('1.2.3f4')
projectpath = 'fakepath'

are_installed([unity])
in_a_project(version: unity.version, path: projectpath)

runner = double("Runner")
allow(U3d::Runner).to receive(:new) { runner }
expect(runner).to receive(:run).with(unity, ['-projectpath', projectpath], raw_logs: nil)

U3d::Commands.run(
options: {},
run_args: []
)
end
end
context 'outside a unity project' do
it 'fails if no unity version specified' do
unity = fake_installation('1.2.3f4')
are_installed(unity)
projectpath = 'fakepath'
in_a_project(version: '1.2.3f4', path: projectpath)

runner = double("Runner")
allow(U3d::Runner).to receive(:new) { runner }

expect do
U3d::Commands.run(
options: {},
run_args: []
)
end.to raise_error U3dCore::Interface::UIError
end
it "fails if the project's unity version isn't installed" do
end
end
end
end
end

0 comments on commit d4ec666

Please sign in to comment.