1

So, I am trying to run the test but I am getting an error says.

Aruba::LaunchError:Command "seedly-calculator.rb" not found in PATH-variable

-seedly-calculator
 -bin
 -src
 -seedly-calculator.rb

I have tried to change the path in rake file but it doesn't work. My seedly-calculator.rb file is in the root directory.

require "rspec/core/rake_task"

namespace :spec do
  desc "Run the functional suite against the CLI"
  RSpec::Core::RakeTask.new(:functional, [] => [:set_path])

  task :set_path do
    project_bin_dir = File.join(File.dirname(File.expand_path(__FILE__)), '..', 'bin')
    ENV['PATH'] = project_bin_dir + ':'+ ENV['PATH']
  end
end

it shows error like:

  Failure/Error: let(:command) { run "seedly-calculator.rb" }

  Aruba::LaunchError:
  Command "seedly-calculator.rb" not found in PATH-variable "/Users/bilaltariq/Desktop/seedly-calculator/functional_spec/bin:/Users/bilaltariq/Desktop/seedly-calculator/functional_spec/exe:/Users/bilaltariq/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/bin:/Users/bilaltariq/Desktop/seedly-calculator/functional_spec/../bin:/Users/bilaltariq/.rbenv/versions/2.6.2/bin:/usr/local/Cellar/rbenv/1.1.1/libexec:/Users/bilaltariq/.rbenv/shims:/Users/bilaltariq/.asdf/shims:/Users/bilaltariq/.asdf/bin:/usr/local/bin:/Users/bilaltariq/.bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin".

I expect it to hit the file so i can write some test. am i doing something wrong?

enter image description here

require 'spec_helper'

RSpec.describe 'Command Validation', type: :aruba do
let(:command) { run "seedly-calculator.rb" }

it "wrong/missing arguments" do
  command.write("lookup\n")
  stop_all_commands
  expect(command.output).to end_with("Missing bank_name argument.\n")
end

end

seedly-calculator.rb:
#!/usr/bin/env ruby

# Complete bin/setup so that after it is
# run, ruby seedly-calculator.rb can be used to launch
# it.

# frozen_string_literal: true

require_relative './src/runner'

if !ARGV.length.zero?
  input = ARGV
  Runner.new.send('process_input', input)
else
  puts "Arguments required!."
end
Nick Bb
  • 601
  • 1
  • 8
  • 18

1 Answers1

0

Update

To run a ruby script using run you need to make sure your ruby script is executable and contains a shebang so your system knows to run it with ruby. Here's example from this starter example

#!/usr/bin/env ruby

file = ARGV[0]

if file.nil? || file.empty?
  abort "aruba-test-cli [file]: Filename is missing"
elsif !File.exist? file
  abort "aruba-test-cli [file]: File does not exist"
end

puts File.read(file).chomp

So in your case you'll need to add this to the first line of your seedly-calculator.rb file

#!/usr/bin/env ruby

Then run this from command line to make it executable.

chmod +x #!/usr/bin/env ruby

I made a simple example forked off the one I reffed above. See this commit

Rspec convention is that it should match the same file structure of your project. It is not a good idea to set PATH manually.

Rake tasks are normally put in a tasks folder so you should have in project root a tasks folder

my_project/tasks/something.rake

Then you should have a spec folder that matches

my_project/spec/tasks/something_spec.rb

Then you should be able to get rid of task :set_path do end block and just run the spec without that.

You should also have a Gemfile to load your gems, run bundle install then invoke your test with

bundle exec rspec spec/tasks/sometask_spec.rb
Community
  • 1
  • 1
lacostenycoder
  • 10,623
  • 4
  • 31
  • 48
  • so do i still need these `project_bin_dir =File.join(File.dirname(File.expand_path(__FILE__)), 'seedly-calculator.rb')` `ENV['PATH'] = project_bin_dir + ':'+ ENV['PATH']` – Nick Bb Mar 24 '19 at 11:50
  • @NickBb nah you can probably remove all that junk – lacostenycoder Mar 24 '19 at 12:06
  • @locostenycoder so i removed it from there and added bundle exec rspec in my execution but i am still getting the same aruba error `Aruba::LaunchError: Command "seedly-calculator.rb" not found in PATH-variable` – Nick Bb Mar 24 '19 at 12:18
  • @locostenycoder very confused. I have all the functionalities working. and rspec is working when my file is inside the bin folder. but i want it outside and everytime i add it outside it shows me error that cant find such file. – Nick Bb Mar 24 '19 at 14:14
  • ie there anyway i can personaly message you! – Nick Bb Mar 24 '19 at 14:15
  • my all files are executable. – Nick Bb Mar 24 '19 at 14:15