Permalink
Browse files

Removing builder and separate the responsability to construct all com…

…mands to a class named ConstructCommand
  • Loading branch information...
1 parent 00a7b8f commit d0f0b0ebe6c9ea4c498da1ff26d37cb48ba7bad3 Tomas D'Stefano committed Jun 5, 2011
View
@@ -11,8 +11,10 @@ group :test do
gem 'aruba', '0.2.1'
gem 'fuubar', '0.0.5'
gem 'ruby-debug19', :require => 'ruby-debug'
+ # gem 'simplecov', '0.4.1', :require => false
end
group :development do
+ gem 'rake', '0.8.7'
gem 'jeweler', '1.6.2'
end
View
@@ -19,20 +19,16 @@ GEM
gherkin (2.2.9)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
- gherkin (2.2.9-java)
- json (~> 1.4.6)
- term-ansicolor (~> 1.0.5)
git (1.2.5)
jeweler (1.6.2)
bundler (~> 1.0)
git (>= 1.2.5)
rake
json (1.4.6)
- json (1.4.6-java)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
notifiers (1.1.0)
- rake (0.9.1)
+ rake (0.8.7)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
@@ -57,7 +53,6 @@ GEM
watchr (0.7)
PLATFORMS
- java
ruby
DEPENDENCIES
@@ -66,6 +61,7 @@ DEPENDENCIES
fuubar (= 0.0.5)
jeweler (= 1.6.2)
notifiers (= 1.1.0)
+ rake (= 0.8.7)
rspec (>= 2.6.0)
ruby-debug19
watchr (= 0.7)
View
@@ -5,9 +5,9 @@ module InfinityTest
autoload :Application, 'infinity_test/application'
autoload :ApplicationFile, 'infinity_test/application_file'
autoload :BinaryPath, 'infinity_test/binary_path'
- autoload :Builder, 'infinity_test/builder'
autoload :Command, 'infinity_test/command'
autoload :Configuration, 'infinity_test/configuration'
+ autoload :ConstructCommand, 'infinity_test/construct_command'
autoload :ContinuousTesting, 'infinity_test/continuous_testing'
autoload :Environment, 'infinity_test/environment'
autoload :Heuristics, 'infinity_test/heuristics'
@@ -65,7 +65,11 @@ def run_global_commands!
# Construct the Global Commands and cache for all suite
#
def global_commands
- @global_commands ||= construct_commands
+ @global_commands ||= construct_command.create.command
+ end
+
+ def construct_command
+ ConstructCommand.new
end
# Return true if the user application has a Gemfile
@@ -74,17 +78,11 @@ def global_commands
def have_gemfile?
File.exist?(gemfile)
end
-
- # Contruct all the commands for the test framework
- #
- def construct_commands
- test_framework.construct_commands
- end
# Construct all the commands for the changed file
#
def construct_commands_for_changed_files(files)
- test_framework.construct_commands(files)
+ ConstructCommand.new(:files_to_run => files).create.command
end
# Return a instance of the test framework class
@@ -121,6 +119,10 @@ def add_heuristics!
def heuristics_users_high_priority!
@watchr.rules.reverse!
end
+
+ def binary_search(environment)
+ test_framework.binary_search(environment)
+ end
# Pass many commands(expecting something that talk like Hash) and run them
# First, triggers all the before each callbacks, run the commands
@@ -139,8 +141,7 @@ def run!(commands)
after_callback.call if after_callback
end
- # Send the message, image and the actual ruby version
- # to show in the notification system
+ # Send the message, image and the actual ruby version to show in the notification system
#
def notify!(options)
if notification_framework
@@ -8,6 +8,7 @@ def self.included(base)
def print_message(gem_name, ruby_version)
puts "\n Ruby => #{ruby_version}: I searched the #{gem_name} binary path and I don't find nothing. You have the #{gem_name} installed in this ruby version?"
+ exit(1)
end
def search_binary(binary_name, options)
@@ -1,66 +0,0 @@
-module InfinityTest
- module Builder
-
- #
- # TODO: Refactoring this Ugly Code
- #
- def construct_command(options)
- binary_name, ruby_version, command, file, environment, specific_options = resolve_options(options)
-
- unless have_binary?(binary_name) || options[:skip_binary?]
- print_message(binary_name, ruby_version)
- else
- command = "#{command} #{decide_files(file)}"
- rvm_ruby_version = "rvm #{ruby_version} ruby #{specific_options}"
-
- if application.have_gemfile? and not application.skip_bundler?
- run_with_bundler!(rvm_ruby_version, command, environment)
- else
- run_without_bundler!(rvm_ruby_version, command)
- end
- end
- end
-
- #
- def run_with_bundler!(rvm_ruby_version, command, environment)
- bundle_binary = search_bundle(environment)
- unless have_binary?(bundle_binary)
- print_message('bundle', environment.expanded_name)
- exit(1)
- else
- %{#{bundle_binary} exec #{rvm_ruby_version} #{command}}
- end
- end
-
- #
- def run_without_bundler!(rvm_ruby_version, command)
- %{#{rvm_ruby_version} #{command}}
- end
-
- #
- # Contruct all the Commands for each ruby instance variable
- # If don't want to run with many rubies, add the current ruby to the rubies instance
- # and create the command with current ruby
- #
- def construct_commands(file=nil)
- @rubies << RVM::Environment.current.environment_name if @rubies.empty?
- construct_rubies_commands(file)
- end
-
- #
- # TODO: Refactoring this Ugly Code
- #
- #
- def resolve_options(options)
- ruby_version = options[:for]
- binary_name = options[:skip_binary?] ? '' : options[:binary]
- load_path = %{-I"#{options[:load_path]}"} if options[:load_path]
- environment = options[:environment]
- file = options[:file]
- specific_options = options[:specific_options]
- command = [ binary_name, load_path].compact.join(' ')
- [binary_name, ruby_version, command, file, environment, specific_options]
- end
-
- end
-end
@@ -0,0 +1,115 @@
+module InfinityTest
+ class ConstructCommand
+ attr_accessor :command, :application, :test_framework, :binary_name, :files_to_run
+
+ attr_reader :version
+ include InfinityTest::Environment
+ include InfinityTest::BinaryPath
+
+ def initialize(options={})
+ @application = InfinityTest.application
+ @test_framework = @application.test_framework
+ @command = {}
+ @files_to_run = options[:files_to_run] || []
+ end
+
+ # Create all commands for each ruby
+ #
+ def create
+ environments do |environment, ruby_version|
+ build_command do |ruby_command|
+ ruby_command.version = ruby_version
+ ruby_command.binary_for(environment)
+ ruby_command.build!
+ end
+ end
+ self
+ end
+
+ # If the user dont pass rubies then will use only the current ruby
+ #
+ def rubies
+ versions_to_run = application.rubies
+ if versions_to_run.empty?
+ current_environment_name
+ else
+ versions_to_run
+ end
+ end
+
+ # Just a method to become more easier to understand the intention of logic
+ #
+ def build_command(&block)
+ block.call(self)
+ end
+
+ # Adding a ruby version as a key in the Hash
+ #
+ def version=(ruby_version)
+ @command[ruby_version] = ''
+ @version = ruby_version
+ end
+
+ # Call binary of rspec two, rspec one or bacon, if using test unit return nothing
+ #
+ def binary_for(environment)
+ if test_framework.respond_to?(:binary_search)
+ @binary_name = application.binary_search(environment)
+ print_message(binary_name, version) unless have_binary?(binary_name)
+ end
+ end
+
+ # Build command for each ruby
+ # Run with bundler if the application have a gemfile and the user don't want to skipped
+ # Run without bundler otherwise
+ #
+ def build!
+ @command[version] = lambda do
+ if application.have_gemfile? and using_bundler?
+ run_with_bundler
+ else
+ run_without_bundler
+ end
+ end.call
+ end
+
+ def run_with_bundler
+ %{#{defaults} -S bundle exec #{binary_name} #{files_to_test}}
+ end
+
+ def run_without_bundler
+ %{#{defaults} -S #{binary_name} #{files_to_test}}
+ end
+
+ def defaults
+ cmd = %{rvm #{version} ruby}
+ cmd << %{#{ruby_options}} if ruby_options
+ cmd
+ end
+
+ def ruby_options
+ options = ""
+ options << specific_options if specific_options
+ options << %{ #{test_framework.defaults}} if test_framework.respond_to?(:defaults)
+ options
+ end
+
+ def specific_options
+ options = application.specific_options
+ if options
+ %{#{options}} unless options.empty?
+ end
+ end
+
+ def files_to_test
+ test_framework.test_files
+ end
+
+ private
+
+ def using_bundler?
+ not application.skip_bundler?
+ end
+
+ end
+end
@@ -6,12 +6,16 @@ module Environment
# This method assumes that the class/module that is included has a method called rubies
#
def environments(&block)
- raise unless block_given?
+ raise "No block passed!" unless block_given?
RVM.environments(rubies).each do |environment|
ruby_version = environment.environment_name
block.call(environment, ruby_version)
end
end
+
+ def current_environment_name
+ RVM::Environment.current.environment_name
+ end
end
end
@@ -2,7 +2,6 @@ module InfinityTest
class TestFramework
include InfinityTest::BinaryPath
include InfinityTest::Environment
- include InfinityTest::Builder
binary :bundle
@@ -60,9 +59,7 @@ def self.parse_results(patterns)
# create_accessors({ :example => '...', :failure => '...'}) # => attr_accessor :example, :failure
#
def self.create_accessors(hash)
- hash.keys.each do |attribute|
- attr_accessor attribute
- end
+ hash.keys.each { |attribute| attr_accessor attribute }
end
# Create the instance pass in the patterns options
@@ -2,8 +2,11 @@ module InfinityTest
module TestLibrary
class Bacon < TestFramework
binary :bacon
+ alias :binary_search :search_bacon
parse_results :specifications => /(\d+) specifications/, :requirements => /(\d+) requirements/, :failures => /(\d+) failure/, :errors => /(\d+) errors/
+ attr_accessor :defaults
+
# Bacon Framework
#
# For more information about the Bacon see: http://github.com/chneukirchen/bacon
@@ -16,25 +19,7 @@ class Bacon < TestFramework
def initialize(options={})
super(options)
@test_pattern = 'spec/**/*_spec.rb'
- end
-
- # Construct all the commands for each ruby
- # First, try to find the bacon binary, and raise/puts an Error if don't find it.
- # After that, verifying if the user have a Gemfile, and if has, run with "bundle exec" command, else will run normally
- #
- def construct_rubies_commands(file=nil)
- commands = {}
- environments do |environment, ruby_version|
- bacon_binary = search_bacon(environment)
- command = construct_command(
- :for => ruby_version,
- :binary => bacon_binary,
- :load_path => 'lib:spec',
- :file => file,
- :environment => environment) || next
- commands[ruby_version] = command
- end
- commands
+ @defaults = %{-I"lib:spec"}
end
def sucess?
Oops, something went wrong.

0 comments on commit d0f0b0e

Please sign in to comment.