File: application_spec.rb

package info (click to toggle)
ruby-launchy 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 304 kB
  • sloc: ruby: 1,051; makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,369 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require "spec_helper"
require "mock_application"

class JunkApp < Launchy::Application
  def self.handles?(uri)
    uri.scheme == "junk"
  end
end

describe Launchy::Application do
  it "registers inherited classes" do
    # rubocop:disable Lint/ConstantDefinitionInBlock
    class Junk2App < Launchy::Application
      def self.handles?(uri)
        uri.scheme == "junk2"
      end
    end
    # rubocop:enable Lint/ConstantDefinitionInBlock
    _(Launchy::Application.children).must_include(Junk2App)
    Launchy::Application.children.delete(Junk2App)
  end

  it "can find an app" do
    _(Launchy::Application.children).must_include(JunkApp)
    _(Launchy::Application.children.size).must_equal 3
    uri = Addressable::URI.parse("junk:///foo")
    _(Launchy::Application.handling(uri)).must_equal(JunkApp)
  end

  it "raises an error if an application cannot be found for the given scheme" do
    uri = Addressable::URI.parse("foo:///bar")
    _(-> { Launchy::Application.handling(uri) }).must_raise(Launchy::ApplicationNotFoundError)
  end

  it "can find open or curl or xdg-open" do
    found = %w[open curl xdg-open].any? do |app|
      Launchy::Application.find_executable(app)
    end
    _(found).must_equal true
  end

  it "does not find xyzzy" do
    _(Launchy::Application.find_executable("xyzzy")).must_be_nil
  end
end