summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/cli_spec.rb32
-rw-r--r--spec/no_tasks_spec.rb2
-rw-r--r--spec/spec_helper.rb25
3 files changed, 49 insertions, 10 deletions
diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb
index aa346ed..1201f72 100644
--- a/spec/cli_spec.rb
+++ b/spec/cli_spec.rb
@@ -2,21 +2,27 @@ 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
- @cli = PgxnUtils::CLI.new
+ 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}", "-p /tmp"
+ skeleton "#{expected_extension}", %w|-p /tmp|
File.should exist("/tmp/#{expected_extension}")
File.should_not exist(expected_extension)
@@ -30,10 +36,9 @@ describe PgxnUtils::CLI do
expected_mail = "[email protected]"
expected_abstract = "Short description"
expected_description = "Very Long description for my cool extension"
- expected_tags = "one two tree"
expected_version = "1.0.0"
- skeleton expected_extension, "-p /tmp -m #{expected_name} -e #{expected_mail} -t #{expected_tags} -a '#{expected_abstract}' -d '#{expected_description}' -v #{expected_version}"
+ 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}"/)
@@ -62,7 +67,8 @@ describe PgxnUtils::CLI do
extension = next_extension
skeleton extension
- Dir["#{extension}/**/*"].sort.should == [
+ Dir["#{extension}/**/{*,.gitignore}"].sort.should == [
+ "#{extension}/.gitignore",
"#{extension}/META.json",
"#{extension}/Makefile",
"#{extension}/README.md",
@@ -80,7 +86,21 @@ describe PgxnUtils::CLI do
].sort
end
- it "should generates a git repo"
+ 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
diff --git a/spec/no_tasks_spec.rb b/spec/no_tasks_spec.rb
index 0117b72..9637882 100644
--- a/spec/no_tasks_spec.rb
+++ b/spec/no_tasks_spec.rb
@@ -7,6 +7,8 @@ describe PgxnUtils::NoTasks do
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
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3ad1c37..d698aba 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -14,19 +14,36 @@ BIN_PATH = File.expand_path('../../bin/pgxn-utils', __FILE__)
DESTINATION_ROOT = File.expand_path('../pgxn_utils', __FILE__)
FileUtils.rm_rf(DESTINATION_ROOT)
+RSpec.configure do |config|
+ # capture method from https://github.com/wycats/thor/blob/master/spec/spec_helper.rb#L36-47
+ def capture(stream)
+ begin
+ stream = stream.to_s
+ eval "$#{stream} = StringIO.new"
+ yield
+ result = eval("$#{stream}").string
+ ensure
+ eval("$#{stream} = #{stream.upcase}")
+ end
+
+ result
+ end
+end
+
+
def next_extension
$counter += 1
"extension.#{$counter}"
end
-def skeleton(extension_name, args=nil)
- run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
+def skeleton(extension_name, args=[])
+ capture(:stdout) { PgxnUtils::CLI.start([ "skeleton", extension_name ] + args) }
end
def change(extension_name, args=nil)
- run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
+ #run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
end
def run_pgxn_utils(task, args)
- system "#{BIN_PATH} #{task.to_s} #{args} >/dev/null"
+ #system "#{BIN_PATH} #{task.to_s} #{args}"
end