Sha256: e653b01e8fa40b6ac6d2389dd8ff0f325b2443e53503220ec2b9024e9d2c42c2

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require File.join(File.dirname(__FILE__),"spec_helper.rb")
require 'stringio'
describe Launchy::Browser do
  it "should find a path to a executable" do
    begin
      File.executable?(Launchy::Browser.new.browser).should == true
    rescue => e
      e.message.should == "Unable to find browser to launch for os family 'nix'."
    end
  end

  it "should handle an http url" do
    Launchy::Browser.handle?("http://www.example.com").should == true
  end

  it "should handle an https url" do
    Launchy::Browser.handle?("https://www.example.com").should == true
  end

  it "should handle an ftp url" do
    Launchy::Browser.handle?("ftp://download.example.com").should == true
  end

  it "should handle an file url" do
    Launchy::Browser.handle?("file:///home/user/index.html").should == true
  end

  it "should not handle a mailto url" do
    Launchy::Browser.handle?("mailto:jeremy@example.com").should == false
  end

  it "creates a default unix application list" do
    begin
      Launchy::Browser.new.nix_app_list.class.should == Array
    rescue => e
      e.message.should == "Unable to find browser to launch for os family 'nix'."
    end
  end

  { "BROWSER" => "/bin/sh",
    "LAUNCHY_BROWSER" => "/bin/sh"}.each_pair do |e,v|
    it "can use environmental variable overrides of #{e} for the browser" do
      ENV[e] = v
      Launchy::Browser.new.browser.should eql(v)
      ENV[e] = nil
    end
  end

  it "reports when it cannot find an browser" do
    old_error = $stderr
    $stderr = StringIO.new
    ENV["LAUNCHY_HOST_OS"] = "testing"
    begin
      browser = Launchy::Browser.new
    rescue => e
      e.message.should =~ /Unable to find browser to launch for os family/m
    end
    ENV["LAUNCHY_HOST_OS"] = nil
    $stderr.string.should =~ /Unable to launch. No Browser application found./m
    $stderr = old_error
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
launchy-0.4.0 spec/browser_spec.rb