spec/program_spec.rb in rprogram-0.1.8 vs spec/program_spec.rb in rprogram-0.2.0

- old
+ new

@@ -2,36 +2,33 @@ require 'spec_helper' require 'classes/ls_program' describe Program do - it "should create a Program from a path" do - prog = Program.new('/usr/bin/ruby') + subject { Program.new('/usr/bin/cc') } + after(:all) { LS.path = nil } - prog.should_not be_nil + it "should create a Program from a path" do + subject.should_not be_nil end it "should derive the program name from a path" do - prog = Program.new('/usr/bin/ruby') - - prog.name.should == 'ruby' + subject.name.should == 'cc' end it "should return the program path when converted to a String" do - prog = Program.new('/usr/bin/ruby') - - prog.to_s.should == '/usr/bin/ruby' + subject.to_s.should == '/usr/bin/cc' end it "should raise an exception for invalid paths" do lambda { Program.new('/totally/doesnt/exist') }.should raise_error(ProgramNotFound) end it "should find a program from a path" do - prog = Program.find_with_path('/usr/bin/dir') + prog = Program.find_with_path('/usr/bin/cc') prog.should_not be_nil end it "should find a program from given paths" do @@ -39,14 +36,22 @@ prog.should_not be_nil end it "should be able to find a program based on the program names" do - ls = nil + ls = LS.find + File.executable?(ls.path).should == true + end + + it "should raise a ProgramNotFound exception if no path/name is valid" do lambda { - ls = LS.find - }.should_not raise_error(ProgramNotFound) + Program.find + }.should raise_error(ProgramNotFound) + end - File.executable?(ls.path).should == true + it "should allow using a default path" do + LS.path = '/usr/bin/dir' + + LS.find.path.should == LS.path end end