Class: InfinityTest::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/infinity_test/configuration.rb

Constant Summary collapse

SUPPORTED_FRAMEWORKS =
[:growl, :lib_notify]
IMAGES_DIR =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'images'))
SUCESS =
'sucess'
FAILURE =
'failure'
PENDING =
'pending'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize the Configuration object that keeps the images, callbacks, rubies and the test framework



23
24
25
26
27
28
29
30
31
# File 'lib/infinity_test/configuration.rb', line 23

def initialize
  @default_dir_image = File.join(IMAGES_DIR, 'simpson')
  @test_framework = :test_unit
  @app_framework = :rubygems
  @sucess_image  = search_image(SUCESS)
  @failure_image = search_image(FAILURE)
  @pending_image = search_image(PENDING)
  @verbose = false
end

Instance Attribute Details

#after_callbackObject

Returns the value of attribute after_callback.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def after_callback
  @after_callback
end

#after_each_ruby_callbackObject

Returns the value of attribute after_each_ruby_callback.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def after_each_ruby_callback
  @after_each_ruby_callback
end

#app_frameworkObject

Returns the value of attribute app_framework.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def app_framework
  @app_framework
end

#before_callbackObject

Returns the value of attribute before_callback.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def before_callback
  @before_callback
end

#before_each_ruby_callbackObject

Returns the value of attribute before_each_ruby_callback.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def before_each_ruby_callback
  @before_each_ruby_callback
end

#before_environment_callbackObject

Returns the value of attribute before_environment_callback.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def before_environment_callback
  @before_environment_callback
end

#cucumberObject

Returns the value of attribute cucumber.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def cucumber
  @cucumber
end

#exceptions_to_ignoreObject

Returns the value of attribute exceptions_to_ignore.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def exceptions_to_ignore
  @exceptions_to_ignore
end

#failure_imageObject

Returns the value of attribute failure_image.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def failure_image
  @failure_image
end

#notification_frameworkObject

Returns the value of attribute notification_framework.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def notification_framework
  @notification_framework
end

#pending_imageObject

Returns the value of attribute pending_image.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def pending_image
  @pending_image
end

#rubiesObject

Returns the value of attribute rubies.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def rubies
  @rubies
end

#specific_optionsObject

Returns the value of attribute specific_options.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def specific_options
  @specific_options
end

#sucess_imageObject

Returns the value of attribute sucess_image.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def sucess_image
  @sucess_image
end

#test_frameworkObject

Returns the value of attribute test_framework.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def test_framework
  @test_framework
end

#verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/infinity_test/configuration.rb', line 6

def verbose
  @verbose
end

Instance Method Details

#after(hook = :all, &block) ⇒ Object

Callback method to handle before or after all run and for each ruby too!

Example:

after(:all) do

clear :terminal

end

after(:each_ruby) do

...

end

Or if you pass not then will use :all option

after do

clear :terminal

end



224
225
226
# File 'lib/infinity_test/configuration.rb', line 224

def after(hook=:all, &block)
  setting_callback(hook, :all => :@after_callback, :each_ruby => :@after_each_ruby_callback, &block)
end

#after_run(&block) ⇒ Object

Callback method to run anything you want, after the run the test suite command

Example:

after_run do

# some code that I want to run after all the rubies run

end



176
177
178
# File 'lib/infinity_test/configuration.rb', line 176

def after_run(&block)
  @after_callback = block
end

#before(hook = :all, &block) ⇒ Object

Callback method to handle before or after all run and for each ruby too!

Example:

before(:all) do

clear :terminal

end

before(:each_ruby) do

...

end

Or if you pass not then will use :all option

before do

clear :terminal

end



199
200
201
202
203
204
# File 'lib/infinity_test/configuration.rb', line 199

def before(hook=:all, &block)
  setting_callback(hook, 
    :all => :@before_callback, 
    :each_ruby => :@before_each_ruby_callback, 
    :env => :@before_environment_callback, &block)
end

#before_run(&block) ⇒ Object

Callback method to run anything you want, before the run the test suite command

Example:

before_run do

clear :terminal

end



164
165
166
# File 'lib/infinity_test/configuration.rb', line 164

def before_run(&block)
  @before_callback = block
end

#clear(option) ⇒ Object

Clear the terminal (Useful in the before callback)



230
231
232
# File 'lib/infinity_test/configuration.rb', line 230

def clear(option)
  system('clear') if option == :terminal
end

#cucumber?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/infinity_test/configuration.rb', line 139

def cucumber?
  @cucumber
end

#heuristics(&block) ⇒ Object

Added heuristics to the User application



242
243
244
245
246
# File 'lib/infinity_test/configuration.rb', line 242

def heuristics(&block)
  @heuristics ||= Heuristics.new
  @heuristics.instance_eval(&block)
  @heuristics
end

#ignore(options = {}) ⇒ Object

Method to use to ignore some dir/files changes

Example:

ignore :exceptions => %w(.svn .hg .git vendor tmp config rerun.txt)

This is useless right now in the Infinity Test because the library only monitoring lib and test/spec/feature folder.



152
153
154
# File 'lib/infinity_test/configuration.rb', line 152

def ignore(options={})
  @exceptions_to_ignore = options[:exceptions] || []
end

#notifications(framework) {|_self| ... } ⇒ Object

Set the notification framework to use with Infinity Test. The supported Notification Frameworks are:

  • Growl

  • Lib-Notify

Here is the example of little Domain Specific Language to use:

notifications :growl do

# block

end

notifications :lib_notify

Yields:

  • (_self)

Yield Parameters:

Raises:



47
48
49
50
51
52
53
# File 'lib/infinity_test/configuration.rb', line 47

def notifications(framework, &block)
  message = "Notification :#{framework} don't supported. The Frameworks supported are: #{SUPPORTED_FRAMEWORKS.join(',')}"
  raise NotificationFrameworkDontSupported, message unless SUPPORTED_FRAMEWORKS.include?(framework)
  @notification_framework = framework
  yield self if block_given?
  self
end

#replace_patterns(&block) ⇒ Object Also known as: before_env



234
235
236
237
# File 'lib/infinity_test/configuration.rb', line 234

def replace_patterns(&block)
  block.call(InfinityTest.application)
  InfinityTest.application
end

#search_image(file) ⇒ Object

Search the sucess, failure or pending images and return the first in the pattern



88
89
90
# File 'lib/infinity_test/configuration.rb', line 88

def search_image(file)
  Dir.glob(File.join(@default_dir_image, file) + '*').first
end

#setting_gemset_for_each_rubies(gemset) ⇒ Object

Setting a gemset for each rubies

setting_gemset_for_each_rubies(‘infinity_test’) # => [‘1.8.7@infinity_test’, ‘1.9.2@infinity_test’]



122
123
124
# File 'lib/infinity_test/configuration.rb', line 122

def setting_gemset_for_each_rubies(gemset)
  @rubies = @rubies.split(',').collect { |ruby| ruby << "@#{gemset}" }.join(',')
end

#show_images(options = {}) ⇒ Object

Set the Success and Failure image to show in the notification framework

show_images :failure => 'Users/tomas/images/my_custom_image.png', :sucess => 'custom_image.jpg'

Or you cant set modes(directory) for show images (please see the images folder in => github.com/tomas-stefano/infinity_test/tree/master/images/ )

show_images :mode => :simpson # => This will show images in the folder http://github.com/tomas-stefano/infinity_test/tree/master/images/simpson
show_images :mode => :street_fighter # => This will show images in folder http://github.com/tomas-stefano/infinity_test/tree/master/images/street_fighter
show_images :mode => '~/My/Mode' # => This will show images in the '~/My/Mode' directory

The Convention in images folder is to set sucess, failure and pending images, and Infinity test will work on these names in the notification framework



68
69
70
71
72
73
# File 'lib/infinity_test/configuration.rb', line 68

def show_images(options={})
  switch_mode!(options[:mode]) if options[:mode]
  @sucess_image  = options[:sucess]  || search_image(SUCESS)
  @failure_image = options[:failure] || search_image(FAILURE)
  @pending_image = options[:pending] || search_image(PENDING)
end

#skip_bundler!Object

InfinityTest try to use bundler if Gemfile is present. This method tell to InfinityTest to not use this convention.



129
130
131
# File 'lib/infinity_test/configuration.rb', line 129

def skip_bundler!
  @skip_bundler = true
end

#skip_bundler?Boolean

Return false if you want the InfinityTest run with bundler

Returns:

  • (Boolean)


135
136
137
# File 'lib/infinity_test/configuration.rb', line 135

def skip_bundler?
  @skip_bundler ? true : false
end

#switch_mode!(mode) ⇒ Object

Switch the image directory to show



77
78
79
80
81
82
83
84
# File 'lib/infinity_test/configuration.rb', line 77

def switch_mode!(mode)
  case mode
  when Symbol
    @default_dir_image = File.join(IMAGES_DIR, mode.to_s)
  when String
    @default_dir_image = File.expand_path(File.join(mode))
  end
end

#use(options = {}) ⇒ Object

The options method to set:

  • test framework

  • ruby versions

  • verbose mode

  • app_framework

Here is the example of Little Domain Language:

use :rubies => [‘1.9.1’, ‘1.9.2’], :test_framework => :rspec

use :rubies => [ ‘1.8.7-p249’, ‘1.9.2@rails3’], :test_framework => :test_unit

use :test_framework => :rspec, :app_framework => :rails



107
108
109
110
111
112
113
114
115
116
# File 'lib/infinity_test/configuration.rb', line 107

def use(options={})
  rubies = options[:rubies]
  @rubies = (rubies.is_a?(Array) ? rubies.join(',') : rubies) || []
  @specific_options = options[:specific_options]
  @test_framework = options[:test_framework] || @test_framework
  @app_framework  = options[:app_framework]  || @app_framework
  @verbose        = options[:verbose]        || @verbose
  @cucumber       = options[:cucumber]
  setting_gemset_for_each_rubies(options[:gemset]) if options[:gemset]
end

#watch(pattern, &block) ⇒ Object

Set #watch methods (For more information see Watchr gem)

If don’t want the heuristics ‘magic’



252
253
254
255
256
# File 'lib/infinity_test/configuration.rb', line 252

def watch(pattern, &block)
  @script ||= InfinityTest.watchr
  @script.watch(pattern, &block)
  @script
end