refactored tests and task
authorDickson S. Guedes <[email protected]>
Thu, 12 May 2011 00:12:19 +0000 (21:12 -0300)
committerDickson S. Guedes <[email protected]>
Thu, 12 May 2011 00:12:19 +0000 (21:12 -0300)
- 'create_extension' changed to 'sekeleton'
- tests are refactored
- a 'target' option was added to 'skeleton'

Rakefile
lib/pgxn_utils/cli.rb
spec/cli_spec.rb
spec/spec_helper.rb

index 732bec3584009298ccffd5295600d67be8bbd81d..32dc7c9327544b0fb51c9b211dc48dc5320cbac3 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -6,7 +6,8 @@ require 'rspec/core/rake_task'
 desc "Run RSpec"
 RSpec::Core::RakeTask.new do |t|
   t.verbose = false
-  t.rspec_opts = %w(-fs --color)
+  #t.rspec_opts = %w(-fs --color)
+  t.rspec_opts = %w(--color)
   #dont show warnings here yet
   #t.ruby_opts  = %w(-w)
 end
index 9b8f22967d7f9ae002ea51c659b1ecfd9355c3d1..c6e53f4e5273251b18e9f85df93ef6856d08a1e9 100644 (file)
@@ -1,32 +1,36 @@
 module PgxnUtils
   class CLI < Thor
-    attr_accessor :extension_name, :author_name, :author_mail
+    attr_accessor :extension_name, :target, :author_name, :author_mail
     attr_accessor :short_description, :long_description, :tags
 
     include Thor::Actions
 
-    desc "create_extension", "Creates an extension skeleton in current directory. Accepts a full path as extension name."
-    method_option :extension_name, :aliases => "-e", :required => true
-    method_option :author_name, :aliases => "-n", :type => :string, :default => "Your Name Here"
-    method_option :author_mail, :aliases => "-m", :type => :string, :default => "[email protected]"
-    method_option :tags, :aliases => "-t", :type => :array
-    method_option :short_description, :aliases => "-s", :type => :string, :default => "A short description"
-    method_option :long_description, :aliases => "-l", :type => :string , :default => "A long description"
+    desc "skeleton extension_name", "Creates an extension skeleton in current directory."
+    method_option :target,            :aliases => "-p", :default => "."
+    method_option :author_name,       :aliases => "-n", :type => :string,   :default => "Your Name Here"
+    method_option :author_mail,       :aliases => "-m", :type => :string,   :default => "[email protected]"
+    method_option :tags,              :aliases => "-t", :type => :array
+    method_option :short_description, :aliases => "-s", :type => :string,   :default => "A short description"
+    method_option :long_description,  :aliases => "-l", :type => :string ,  :default => "A long description"
+
+    def skeleton(extension_name)
+      self.set_accessors extension_name
 
-    def create_extension
-      self.set_accessors
       directory "root", extension_name
     end
 
     no_tasks do
-      def set_accessors
-        self.destination_root = File.dirname(options[:extension_name]) || destination_root
-        self.extension_name = File.basename(options[:extension_name]) 
-        self.author_name = options[:author_name] 
-        self.author_mail = options[:author_mail] 
-        self.tags = options[:tags] 
-        self.short_description = options[:short_description] 
+      def set_accessors(extension_name="your_extension_name")
+        self.extension_name = extension_name
+
+        self.target = options[:target]
+        self.author_name = options[:author_name]
+        self.author_mail = options[:author_mail]
+        self.tags = options[:tags]
+        self.short_description = options[:short_description]
         self.long_description = options[:long_description]
+
+        self.destination_root = target
       end
     end
 
index c78f4456c9cd3fe46c184d44bb8a0aa0c3c15c21..1d727e6d06d2a46380697cc0960b555c9b4cf7b4 100644 (file)
@@ -3,68 +3,85 @@ require File.expand_path('spec/spec_helper')
 describe PgxnUtils::CLI do
 
   after(:all) do
-    system "rm -rf /tmp/*.#{$$}"
+    system "rm -rf /tmp/extension.*"
+    system "rm -rf extension.*"
   end
 
-  context "create extension" do
+  context "create skeleton" do
     before(:each) do
       @cli = PgxnUtils::CLI.new
     end
 
-    it "should set destination root and extension name when a path is supplied" do
-      extension_path = "/tmp/my_cool_extension.#{$$}"
-      @cli.create_extension(extension_path)
-      @cli.extension_name.should == "my_cool_extension.#{$$}"
-      @cli.destination_root.should == "/tmp"
+    it "should accepts or not a target" do
+      expected_extension = next_extension
+
+      File.should_not exist(expected_extension)
+      skeleton "#{expected_extension}", "-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 and email" do
-      @cli.create_extension("/tmp/guedes.extension.#{$$}","Guedes","guedes@nonexistant")
-      @cli.author_name.should == "Guedes"
-      @cli.author_mail.should == "guedes@nonexistant"
+    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_short_description = "Short description"
+      expected_long_description = "Very Long description for my cool extension"
+      expected_tags = "one two tree"
+
+      skeleton expected_extension, "-p /tmp -n #{expected_name} -m #{expected_mail} -t #{expected_tags} -s '#{expected_short_description}' -l '#{expected_long_description}'"
+
+      meta = File.read("/tmp/#{expected_extension}/META.json")
+      meta.should match(/"name": "#{expected_extension}"/)
+      meta.should match(/"abstract": "#{expected_short_description}"/)
+      meta.should match(/"description": "#{expected_long_description}"/)
+      meta.should match(/"#{expected_name} <#{expected_mail}>"/)
+      meta.should match(/"file": "sql\/#{expected_extension}.sql"/)
+      meta.should match(/"docfile": "doc\/#{expected_extension}.md"/)
+      meta.should 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 = '\/#{expected_extension}'/)
     end
 
-    it "should generates an skeleton" do
-      extension_path = "/tmp/extension_test.#{$$}"
-
-      @cli.create_extension(extension_path)
-
-      extension_name = @cli.extension_name
-      extension_root = @cli.destination_root
-
-      Dir["#{extension_path}/**/*"].sort.should == [
-        "#{extension_path}/META.json",
-        "#{extension_path}/Makefile",
-        "#{extension_path}/doc",
-        "#{extension_path}/doc/#{extension_name}.md",
-        "#{extension_path}/sql",
-        "#{extension_path}/sql/#{extension_name}.sql",
-        "#{extension_path}/sql/uninstall_#{extension_name}.sql",
-        "#{extension_path}/test",
-        "#{extension_path}/test/expected",
-        "#{extension_path}/test/expected/base.out",
-        "#{extension_path}/test/sql",
-        "#{extension_path}/test/sql/base.sql",
-        "#{extension_path}/#{extension_name}.control"
+    it "should generates a skeleton" do
+      extension = next_extension
+      skeleton extension
+
+      Dir["#{extension}/**/*"].sort.should == [
+        "#{extension}/META.json",
+        "#{extension}/Makefile",
+        "#{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 test skeleton"
-    it "should accepts name and email as comand line"
-    it "should accepts short and long description as command line"
+    it "should generates a git repo"
   end
 
-  context "tests" do
-    it "should run tests and returns correct results"
+  context "bundle" do
+    it "should bundle to zip by default"
+    it "should create the name in semver spec"
   end
 
-  context "invoke external tasks" do
-    it "should execute sucessfuly"
-    it "should ignores non-existant external tasks"
+  context "release" do
+    it "should send the bundle to PGXN"
   end
 
-  context "manage extension" do
-    it "should update and tag version"
-    it "should upload to pgxn.org"
-  end
 end
index ca31bc0bb29ec206e0c8ef7aa3905d84acc27748..f078b0b95d59b0a81bb22d7b8aae99b450249332 100644 (file)
@@ -3,3 +3,24 @@ $:.unshift File.expand_path('../../lib', __FILE__)
 
 require 'rspec'
 require 'pgxn_utils'
+
+$counter = 0
+
+LIB_PATH = File.expand_path('../../lib', __FILE__)
+BIN_PATH = File.expand_path('../../bin/pgxn_utils', __FILE__)
+
+DESTINATION_ROOT = File.expand_path('../pgxn_utils', __FILE__)
+FileUtils.rm_rf(DESTINATION_ROOT)
+
+def next_extension
+  $counter += 1
+  "extension.#{$counter}"
+end
+
+def skeleton(extension_name, args=nil)
+  run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
+end
+
+def run_pgxn_utils(task, args)
+  system "#{BIN_PATH} #{task.to_s} #{args} >/dev/null"
+end