diff options
author | Dickson S. Guedes | 2011-05-12 00:12:19 +0000 |
---|---|---|
committer | Dickson S. Guedes | 2011-05-12 00:12:19 +0000 |
commit | bc8c46378f88ee3a5cb232251127835b49f5e795 (patch) | |
tree | 34294c7aba295be2851fb895a87b8286a23402a8 | |
parent | 385af9acda11013d60e24be72a3e806aa8cd9e42 (diff) |
refactored tests and task
- 'create_extension' changed to 'sekeleton'
- tests are refactored
- a 'target' option was added to 'skeleton'
-rw-r--r-- | Rakefile | 3 | ||||
-rw-r--r-- | lib/pgxn_utils/cli.rb | 38 | ||||
-rw-r--r-- | spec/cli_spec.rb | 107 | ||||
-rw-r--r-- | spec/spec_helper.rb | 21 |
4 files changed, 106 insertions, 63 deletions
@@ -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 diff --git a/lib/pgxn_utils/cli.rb b/lib/pgxn_utils/cli.rb index 9b8f229..c6e53f4 100644 --- a/lib/pgxn_utils/cli.rb +++ b/lib/pgxn_utils/cli.rb @@ -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 diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index c78f445..1d727e6 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ca31bc0..f078b0b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 |