summaryrefslogtreecommitdiff
path: root/spec/cli_spec.rb
blob: 1201f72b62514258a31508aa7511c19f49492756 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require File.expand_path('spec/spec_helper')

describe PgxnUtils::CLI do

  before(:all) do
	FileUtils.mv "META.json", "meta.json"
  end

  after(:all) do
	FileUtils.mv "meta.json", "META.json"
    system "rm -rf /tmp/extension.*"
    system "rm -rf extension.*"
  end

  context "#skeleton" do
    before(:each) do
		system "rm -rf /tmp/extension.*"
		system "rm -rf extension.*"
    end

    it "should accepts or not a target" do
      expected_extension = next_extension

      File.should_not exist(expected_extension)
      skeleton "#{expected_extension}", %w|-p /tmp|
      File.should exist("/tmp/#{expected_extension}")

      File.should_not exist(expected_extension)
      skeleton "#{expected_extension}"
      File.should exist(expected_extension)
    end

    it "should store author's name, email, short_description, long_desctiption, tags" do
      expected_extension = next_extension
      expected_name = "Guedes"
      expected_mail = "[email protected]"
      expected_abstract = "Short description"
      expected_description = "Very Long description for my cool extension"
      expected_version = "1.0.0"

      skeleton expected_extension, %W|-p /tmp -m #{expected_name} -e #{expected_mail} -t one two tree -a #{expected_abstract} -d #{expected_description} -v #{expected_version}|

      meta = File.read("/tmp/#{expected_extension}/META.json")
      meta.should match(/"name": "#{expected_extension}"/)
      meta.should match(/"abstract": "#{expected_abstract}"/)
      meta.should match(/"description": "#{expected_description}"/)
      meta.should match(/"version": "#{expected_version}"/)
      meta.should match(/"license": "postgresql"/)
      meta.should match(/"release_status": "unstable"/)
      #TODO: I want define how split this from META
      #meta.should match(/"#{expected_name} <#{expected_mail}>"/)
      meta.should match(/"#{expected_name}"/)
      meta.should match(/"file": "sql\/#{expected_extension}.sql"/)
      meta.should match(/"docfile": "doc\/#{expected_extension}.md"/)
      meta.should_not match(/"generated_by": #{expected_name}/)
      meta.should match(/"tags": \[ "one","two","tree" \],/)

      makefile = File.read("/tmp/#{expected_extension}/Makefile")
      makefile.should match(/EXTENSION    = #{expected_extension}/)

      control = File.read("/tmp/#{expected_extension}/#{expected_extension}.control")
      control.should match(/module_pathname = '\$libdir\/#{expected_extension}'/)
      control.should match(/default_version = '#{expected_version}'/)
    end

    it "should generates a skeleton" do
      extension = next_extension
      skeleton extension

      Dir["#{extension}/**/{*,.gitignore}"].sort.should == [
        "#{extension}/.gitignore",
        "#{extension}/META.json",
        "#{extension}/Makefile",
        "#{extension}/README.md",
        "#{extension}/doc",
        "#{extension}/doc/#{extension}.md",
        "#{extension}/sql",
        "#{extension}/sql/#{extension}.sql",
        "#{extension}/sql/uninstall_#{extension}.sql",
        "#{extension}/test",
        "#{extension}/test/expected",
        "#{extension}/test/expected/base.out",
        "#{extension}/test/sql",
        "#{extension}/test/sql/base.sql",
        "#{extension}/#{extension}.control"
      ].sort
    end

	it "should generates a git repo with --git" do
		expected_extension = next_extension
		skeleton "#{expected_extension}", %w|--git|

		File.should exist("#{expected_extension}/.git")
		lambda{ Grit::Repo.new(expected_extension) }.should_not raise_error
	end

	it "should not generates a git repo with --no-git" do
		expected_extension = next_extension
		skeleton "#{expected_extension}", %w|--no-git|

		File.should_not exist("#{expected_extension}/.git")
		lambda{ Grit::Repo.new(expected_extension) }.should raise_error
	end
  end

  context "#change" do
    it "should change things"
  end

  context "#bundle" do
    it "should bundle to zip by default"
    it "should create the name in semver spec"
  end

  context "#release" do
    it "should send the bundle to PGXN"
  end

end