summaryrefslogtreecommitdiff
path: root/spec/no_tasks_spec.rb
blob: 9637882d861f9c2c1796f82c901ade720c9e9bbc (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require File.expand_path('spec/spec_helper')

describe PgxnUtils::NoTasks do
  include PgxnUtils::NoTasks
  include FileUtils

  after(:all) do
    rm_r("/tmp/teste")
    rm_r("/tmp/teste2")

    PgxnUtils::NoTasks.send(:remove_method, :options)
  end

  context "#resolve_extension_path_and_name" do
    it "should raise error when no extension name was supplied" do
      PgxnUtils::NoTasks.send(:define_method, :options) do
        { :target => "/something" }
      end
      extension_name = "."
      lambda {resolve_extension_path_and_name(extension_name)}.should raise_error(ArgumentError)
    end

    it "should return correctly if target is '.'" do
      PgxnUtils::NoTasks.send(:define_method, :options) do
        { :target => "." }
      end

      original_dir = File.expand_path(".")
      destination_dir = "/tmp/teste"
      mkdir destination_dir
      cd destination_dir

      extension_name = "teste"
      resolved_path, resolved_name = resolve_extension_path_and_name(extension_name)

      cd original_dir

      resolved_path.should == "#{destination_dir}/#{extension_name}"
      resolved_name.should == extension_name
    end

    it "should return correctly when target are not '.' and a extension name was specified" do
      PgxnUtils::NoTasks.send(:define_method, :options) do
        { :target => "/tmp" }
      end

      original_dir = File.expand_path(".")
      destination_dir = "/tmp/teste2"
      mkdir destination_dir
      cd destination_dir

      extension_name = "teste2"
      resolved_path, resolved_name = resolve_extension_path_and_name(extension_name)

      cd original_dir

      resolved_path.should == destination_dir
      resolved_name.should == extension_name
    end
  end
end