Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial import

  • Loading branch information...
commit f3201f1d98041f6ad7154432bf970f04d765b4df 0 parents
@fabiokung authored
4 History.txt
@@ -0,0 +1,4 @@
+== 0.0.1 2008-11-25
+
+* 1 major enhancement:
+ * Initial release
16 Manifest.txt
@@ -0,0 +1,16 @@
+History.txt
+Manifest.txt
+PostInstall.txt
+README.rdoc
+Rakefile
+features/development.feature
+features/steps/common.rb
+features/steps/env.rb
+lib/rfactor.rb
+script/console
+script/destroy
+script/generate
+spec/rfactor_spec.rb
+spec/spec.opts
+spec/spec_helper.rb
+tasks/rspec.rake
7 PostInstall.txt
@@ -0,0 +1,7 @@
+
+For more information on rfactor, see http://rfactor.rubyforge.org
+
+NOTE: Change this information in PostInstall.txt
+You can also delete it if you don't want it.
+
+
48 README.rdoc
@@ -0,0 +1,48 @@
+= rfactor
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2008 Fabio Kung
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 Rakefile
@@ -0,0 +1,28 @@
+%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
+require File.dirname(__FILE__) + '/lib/rfactor'
+
+# Generate all the Rake tasks
+# Run 'rake -T' to see list of generated tasks (from gem root directory)
+$hoe = Hoe.new('rfactor', Rfactor::VERSION) do |p|
+ p.developer('Fabio Kung', 'fabio.kung@gmail.com')
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
+ p.rubyforge_name = p.name # TODO this is default value
+ p.extra_deps = [
+ ['ParseTree','>= 3.0.2']
+ ]
+ p.extra_dev_deps = [
+ ['newgem', ">= #{::Newgem::VERSION}"]
+ ]
+
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
+ p.rsync_args = '-av --delete --ignore-errors'
+end
+
+require 'newgem/tasks' # load /tasks/*.rake
+Dir['tasks/**/*.rake'].each { |t| load t }
+
+# TODO - want other tests/tasks run by default? Add them to the list
+task :default => [:spec, :features]
13 features/development.feature
@@ -0,0 +1,13 @@
+Feature: Development processes of newgem itself (rake tasks)
+
+ As a Newgem maintainer or contributor
+ I want rake tasks to maintain and release the gem
+ So that I can spend time on the tests and code, and not excessive time on maintenance processes
+
+ Scenario: Generate RubyGem
+ Given this project is active project folder
+ And 'pkg' folder is deleted
+ When task 'rake gem' is invoked
+ Then folder 'pkg' is created
+ And file with name matching 'pkg/*.gem' is created else you should run "rake manifest" to fix this
+ And gem spec key 'rdoc_options' contains /--mainREADME.rdoc/
174 features/steps/common.rb
@@ -0,0 +1,174 @@
+def in_project_folder(&block)
+ project_folder = @active_project_folder || @tmp_root
+ FileUtils.chdir(project_folder, &block)
+end
+
+def in_home_folder(&block)
+ FileUtils.chdir(@home_path, &block)
+end
+
+Given %r{^a safe folder} do
+ FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp"
+ FileUtils.mkdir_p @tmp_root
+ FileUtils.mkdir_p @home_path = File.expand_path(File.join(@tmp_root, "home"))
+ @lib_path = File.expand_path(File.dirname(__FILE__) + '/../../lib')
+ Given "env variable $HOME set to '#{@home_path}'"
+end
+
+Given %r{^this project is active project folder} do
+ Given "a safe folder"
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
+end
+
+Given %r{^env variable \$([\w_]+) set to '(.*)'} do |env_var, value|
+ ENV[env_var] = value
+end
+
+def force_local_lib_override(project_name = @project_name)
+ rakefile = File.read(File.join(project_name, 'Rakefile'))
+ File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
+ f << "$:.unshift('#{@lib_path}')\n"
+ f << rakefile
+ end
+end
+
+def setup_active_project_folder project_name
+ @active_project_folder = File.join(@tmp_root, project_name)
+ @project_name = project_name
+end
+
+Given %r{'(.*)' folder is deleted} do |folder|
+ in_project_folder do
+ FileUtils.rm_rf folder
+ end
+end
+
+When %r{^'(.*)' generator is invoked with arguments '(.*)'$} do |generator, arguments|
+ FileUtils.chdir(@active_project_folder) do
+ if Object.const_defined?("APP_ROOT")
+ APP_ROOT.replace(FileUtils.pwd)
+ else
+ APP_ROOT = FileUtils.pwd
+ end
+ run_generator(generator, arguments.split(' '), SOURCES)
+ end
+end
+
+When %r{run executable '(.*)' with arguments '(.*)'} do |executable, arguments|
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
+ FileUtils.chdir(@active_project_folder) do
+ system "ruby #{executable} #{arguments} > #{@stdout}"
+ end
+end
+
+When %r{^task 'rake (.*)' is invoked$} do |task|
+ @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
+ FileUtils.chdir(@active_project_folder) do
+ system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
+ end
+end
+
+Then %r{^folder '(.*)' is created} do |folder|
+ in_project_folder do
+ File.exists?(folder).should be_true
+ end
+end
+
+Then %r{^file '(.*)' (is|is not) created} do |file, is|
+ in_project_folder do
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
+ end
+end
+
+Then %r{^file with name matching '(.*)' is created} do |pattern|
+ in_project_folder do
+ Dir[pattern].should_not be_empty
+ end
+end
+
+Then %r{gem file '(.*)' and generated file '(.*)' should be the same} do |gem_file, project_file|
+ File.exists?(gem_file).should be_true
+ File.exists?(project_file).should be_true
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
+ project_file_contents.should == gem_file_contents
+end
+
+Then %r{^output same as contents of '(.*)'$} do |file|
+ expected_output = File.read(File.join(File.dirname(__FILE__) + "/../expected_outputs", file))
+ actual_output = File.read(File.dirname(__FILE__) + "/../../tmp/#{@stdout}")
+ actual_output.should == expected_output
+end
+
+Then %r{^(does|does not) invoke generator '(.*)'$} do |does_invoke, generator|
+ actual_output = File.read(File.dirname(__FILE__) + "/../../tmp/#{@stdout}")
+ does_invoke == "does" ?
+ actual_output.should(match(/dependency\s+#{generator}/)) :
+ actual_output.should_not(match(/dependency\s+#{generator}/))
+end
+
+Then %r{help options '(.*)' and '(.*)' are displayed} do |opt1, opt2|
+ actual_output = File.read(@stdout)
+ actual_output.should match(/#{opt1}/)
+ actual_output.should match(/#{opt2}/)
+end
+
+Then %r{^output (does|does not) match \/(.*)\/} do |does, regex|
+ actual_output = File.read(@stdout)
+ (does == 'does') ?
+ actual_output.should(match(/#{regex}/)) :
+ actual_output.should_not(match(/#{regex}/))
+end
+
+Then %r{^contents of file '(.*)' (does|does not) match \/(.*)\/} do |file, does, regex|
+ in_project_folder do
+ actual_output = File.read(file)
+ (does == 'does') ?
+ actual_output.should(match(/#{regex}/)) :
+ actual_output.should_not(match(/#{regex}/))
+ end
+end
+
+Then %r{^all (\d+) tests pass} do |expected_test_count|
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
+ actual_output = File.read(@stdout)
+ actual_output.should match(expected)
+end
+
+Then %r{^all (\d+) examples pass} do |expected_test_count|
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
+ actual_output = File.read(@stdout)
+ actual_output.should match(expected)
+end
+
+Then %r{^yaml file '(.*)' contains (\{.*\})} do |file, yaml|
+ in_project_folder do
+ yaml = eval yaml
+ YAML.load(File.read(file)).should == yaml
+ end
+end
+
+Then %r{^Rakefile can display tasks successfully} do
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
+ FileUtils.chdir(@active_project_folder) do
+ system "rake -T > #{@stdout} 2> #{@stdout}"
+ end
+ actual_output = File.read(@stdout)
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
+end
+
+Then %r{^task 'rake (.*)' is executed successfully} do |task|
+ @stdout.should_not be_nil
+ actual_output = File.read(@stdout)
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
+ actual_output.should_not match(/Error/i)
+end
+
+Then %r{^gem spec key '(.*)' contains \/(.*)\/} do |key, regex|
+ in_project_folder do
+ gem_file = Dir["pkg/*.gem"].first
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
+ spec_value = gem_spec.send(key.to_sym)
+ spec_value.to_s.should match(/#{regex}/)
+ end
+end
6 features/steps/env.rb
@@ -0,0 +1,6 @@
+require File.dirname(__FILE__) + "/../../lib/rfactor"
+
+gem 'cucumber'
+require 'cucumber'
+gem 'rspec'
+require 'spec'
9 lib/rfactor.rb
@@ -0,0 +1,9 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+module Rfactor
+ VERSION = '0.0.1'
+end
+
+require 'rubygems'
+require 'parse_tree'
10 script/console
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+# File: script/console
+irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
+
+libs = " -r irb/completion"
+# Perhaps use a console_lib to store any extra methods I may want available in the cosole
+# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
+libs << " -r #{File.dirname(__FILE__) + '/../lib/rfactor.rb'}"
+puts "Loading rfactor gem"
+exec "#{irb} #{libs} --simple-prompt"
14 script/destroy
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/destroy'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Destroy.new.run(ARGV)
14 script/generate
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/generate'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Generate.new.run(ARGV)
11 spec/rfactor_spec.rb
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/spec_helper.rb'
+
+# Time to add your specs!
+# http://rspec.info/
+describe "Place your specs here" do
+
+ it "find this spec in spec directory" do
+ violated "Be sure to write your specs"
+ end
+
+end
2  spec/spec.opts
@@ -0,0 +1,2 @@
+--colour
+--format specdoc
10 spec/spec_helper.rb
@@ -0,0 +1,10 @@
+begin
+ require 'spec'
+rescue LoadError
+ require 'rubygems'
+ gem 'rspec'
+ require 'spec'
+end
+
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+require 'rfactor'
21 tasks/rspec.rake
@@ -0,0 +1,21 @@
+begin
+ require 'spec'
+rescue LoadError
+ require 'rubygems'
+ require 'spec'
+end
+begin
+ require 'spec/rake/spectask'
+rescue LoadError
+ puts <<-EOS
+To use rspec for testing you must install rspec gem:
+ gem install rspec
+EOS
+ exit(0)
+end
+
+desc "Run the specs under spec/models"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_opts = ['--options', "spec/spec.opts"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
Please sign in to comment.
Something went wrong with that request. Please try again.