Class: InfinityTest::Application

Inherits:
Object
  • Object
show all
Includes:
ApplicationLibrary, TestLibrary, Notifiers
Defined in:
lib/infinity_test/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Initialize the Application object with the configuration instance to load configuration and set properly



12
13
14
15
# File 'lib/infinity_test/application.rb', line 12

def initialize
  @config = InfinityTest.configuration
  @watchr = InfinityTest.watchr
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/infinity_test/application.rb', line 7

def config
  @config
end

#global_commandsObject

Construct the Global Commands and cache for all suite



70
71
72
# File 'lib/infinity_test/application.rb', line 70

def global_commands
  @global_commands
end

#watchrObject

Returns the value of attribute watchr.



7
8
9
# File 'lib/infinity_test/application.rb', line 7

def watchr
  @watchr
end

Instance Method Details

#add_heuristics!Object

Triggers the #add_heuristics! method in the application_framework



182
183
184
# File 'lib/infinity_test/application.rb', line 182

def add_heuristics!
  app_framework.add_heuristics!
end

#after_callbackObject

Return the block object setting in the config file



100
101
102
# File 'lib/infinity_test/application.rb', line 100

def after_callback
  config.after_callback
end

#after_each_ruby_callbackObject

Return the block object setting in the after(:each_ruby) block



112
113
114
# File 'lib/infinity_test/application.rb', line 112

def after_each_ruby_callback
  config.after_each_ruby_callback
end

#all_test_filesObject

Return all the tests files in the User application



298
299
300
# File 'lib/infinity_test/application.rb', line 298

def all_test_files
  test_framework.all_files
end

#app_frameworkObject

Return a instance of the app framework class



170
171
172
# File 'lib/infinity_test/application.rb', line 170

def app_framework
  @app_framework ||= setting_app_framework
end

#before_callbackObject

Return the block object setting in the config file



94
95
96
# File 'lib/infinity_test/application.rb', line 94

def before_callback
  config.before_callback
end

#before_each_ruby_callbackObject

Return the block object setting in the before(:each_ruby) block



106
107
108
# File 'lib/infinity_test/application.rb', line 106

def before_each_ruby_callback
  config.before_each_ruby_callback
end

#construct_commandsObject

Contruct all the commands for the test framework



151
152
153
# File 'lib/infinity_test/application.rb', line 151

def construct_commands
  test_framework.construct_commands
end

#failure_imageObject

Return the failure image to show in the notifications



82
83
84
# File 'lib/infinity_test/application.rb', line 82

def failure_image
  config.failure_image
end

#files_to_run!(options) ⇒ Object

Return the files that match by the options This very used in the #run method called in the heuristics instances

Example:

files_to_run!(:all => :files) # => Return all test files
files_to_run!(:all => :files, :in_dir => :models) # => Return all the test files in the models directory
files_to_run!(:test_for => match_data)  # => Return the tests that match with the MatchData Object
files_to_run!(:test_for => match_data, :in_dir => :controllers) # => Return the tests that match with the MatchData Object
files_to_run!(match_data) # => return the test file


259
260
261
262
263
264
# File 'lib/infinity_test/application.rb', line 259

def files_to_run!(options)
  files = search_files_to_run!(options)
  # Fix fo Test::Unit - But this is not responsability of the Application instances - Refactoring this
  files = "#{test_framework.test_loader} #{files}" if test_framework.respond_to?(:test_loader)
  files
end

#have_gemfile?Boolean

Return true if the user application has a Gemfile Return false if not exist the Gemfile

Returns:

  • (Boolean)


138
139
140
# File 'lib/infinity_test/application.rb', line 138

def have_gemfile?
  File.exist?(gemfile)
end

#heuristicsObject

Return all the Heuristics of the application



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

def heuristics
  config.instance_variable_get(:@heuristics)
end

#heuristics_users_high_priority!Object



186
187
188
# File 'lib/infinity_test/application.rb', line 186

def heuristics_users_high_priority!
  @watchr.rules.reverse!
end

#image_to_showObject

If the test pass, show the sucess image If is some pending test, show the pending image If the test fails, show the failure image



238
239
240
241
242
243
244
245
246
# File 'lib/infinity_test/application.rb', line 238

def image_to_show
  if test_framework.failure?
    failure_image
  elsif test_framework.pending?
    pending_image
  else
    sucess_image
  end
end

#load_configuration_fileObject

Load the Configuration file

Command line options can be persisted in a .infinity_test file in a project. You can also store a .infinity_test file in your home directory (~/.infinity_test) with global options.

Precedence is: command line ./.infinity_test ~/.infinity_test

Example:

~/.infinity_test -> infinity_test { notifications :growl }

./.infinity_test -> infinity_test { notifications :lib_notify }  # High Priority

After the load the Notifications Framework will be Lib Notify



40
41
42
43
# File 'lib/infinity_test/application.rb', line 40

def load_configuration_file
  load_global_configuration    # Separate global and local configuration
  load_project_configuration   # because it's more easy to test
end

#load_configuration_file_or_read_the_options!(options) ⇒ Object



17
18
19
20
# File 'lib/infinity_test/application.rb', line 17

def load_configuration_file_or_read_the_options!(options)
  load_configuration_file
  setup!(options)
end

#notification_frameworkObject

Return the notification_framework setting in the configuration file Maybe is: :growl, :lib_notify



210
211
212
# File 'lib/infinity_test/application.rb', line 210

def notification_framework
  config.notification_framework
end

#notify!(options) ⇒ Object

Send the message,image and the actual ruby version to show in the notification system



216
217
218
219
220
221
222
223
224
# File 'lib/infinity_test/application.rb', line 216

def notify!(options)
  if notification_framework        
    message = parse_results(options[:results])
    title = options[:ruby_version]
    send(notification_framework).title(title).message(message).image(image_to_show).notify!
  else
    # skip(do nothing) when not have notification framework
  end
end

#parse_results(results) ⇒ Object

Parse the results for each command to the test framework

app.parse_results([‘.….’,‘108 examples’]) # => ‘108 examples’



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

def parse_results(results)
  test_framework.parse_results(results)
end

#pending_imageObject

Return the pending image to show in the notifications



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

def pending_image
  config.pending_image
end

#rubiesObject

Return the rubies setting in the config file or the command line



118
119
120
# File 'lib/infinity_test/application.rb', line 118

def rubies
  config.rubies
end

#run!(commands) ⇒ Object

Pass many commands(expecting something that talk like Hash) and run them First, triggers all the before each callbacks, run the commands and last, triggers after each callbacks



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/infinity_test/application.rb', line 194

def run!(commands)
  before_callback.call if before_callback

  commands.each do |ruby_version, command|
    call_each_ruby_callback(:before_each_ruby_callback, ruby_version)
    command = say_the_ruby_version_and_run_the_command!(ruby_version, command) # This method exist because it's more easier to test
    notify!(:results => command.results, :ruby_version => ruby_version)
    call_each_ruby_callback(:after_each_ruby_callback, ruby_version)
  end

  after_callback.call if after_callback
end

#run_commands_for_file(file) ⇒ Object

Run commands for a file If dont have a file, do nothing



305
306
307
308
309
310
# File 'lib/infinity_test/application.rb', line 305

def run_commands_for_file(file)
  if file and !file.empty?
    commands = test_framework.construct_commands(file)
    run!(commands)
  end
end

#run_global_commands!Object

Run the global commands



64
65
66
# File 'lib/infinity_test/application.rb', line 64

def run_global_commands!
  run!(global_commands)
end

#say_the_ruby_version_and_run_the_command!(ruby_version, command) ⇒ Object



312
313
314
315
316
# File 'lib/infinity_test/application.rb', line 312

def say_the_ruby_version_and_run_the_command!(ruby_version, command)
  puts; puts "* { :ruby => #{ruby_version} }"
  puts command if verbose?
  Command.new(:ruby_version => ruby_version, :command => command).run!
end

#search_file(options) ⇒ Object

Search files that matches with the pattern



291
292
293
294
# File 'lib/infinity_test/application.rb', line 291

def search_file(options)
  files = all_test_files.grep(/#{options[:pattern]}/i)      
  search_files_in_dir(files, :in_dir => options[:in_dir]).join(' ')
end

#search_files_in_dir(files, options) ⇒ Object

Search files under the dir(s) specified



281
282
283
284
285
286
287
# File 'lib/infinity_test/application.rb', line 281

def search_files_in_dir(files, options)
  dirs = [options[:in_dir]].compact.flatten
  match_files = dirs.collect do |directory|
     files.select { |file| file.match(directory.to_s) }
  end
  match_files.empty? ? files : match_files
end

#search_files_to_run!(options) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/infinity_test/application.rb', line 266

def search_files_to_run!(options)
  case options
  when MatchData
    options.to_s
  when Hash,Symbol
    if options.equal?(:all) or options.include?(:all)
      search_files_in_dir(all_test_files, :in_dir => options[:in_dir]).join(' ')
    else
      search_file(:pattern => options[:test_for][1], :in_dir => options[:in_dir]) if options.include?(:test_for)
    end
  end      
end

#setup!(options) ⇒ Object

Setup over a precendence show below.

THIS IS NOT RESPONSABILITY OF Application instances!!!



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/infinity_test/application.rb', line 49

def setup!(options)
  config.use(
     :rubies => (options[:rubies] || rubies),
     :specific_options => (options[:specific_options] || specific_options),
     :test_framework => (options[:test_framework] || config.test_framework),
     :app_framework => (options[:app_framework]   || config.app_framework),
     :cucumber => options[:cucumber],
     :verbose => options[:verbose] || config.verbose)
  config.skip_bundler! if options[:skip_bundler?]
  add_heuristics!
  heuristics_users_high_priority!
end

#skip_bundler?Boolean

Return false if you want the InfinityTest run with bundler Return true otherwise

Returns:

  • (Boolean)


145
146
147
# File 'lib/infinity_test/application.rb', line 145

def skip_bundler?
  config.skip_bundler?
end

#specific_optionsObject

Return the rubies specific options in the config file or the command line



124
125
126
# File 'lib/infinity_test/application.rb', line 124

def specific_options
  config.specific_options
end

#sucess_imageObject

Return the sucess image to show in the notifications



76
77
78
# File 'lib/infinity_test/application.rb', line 76

def sucess_image
  config.sucess_image
end

#test_frameworkObject

Return a instance of the test framework class



157
158
159
# File 'lib/infinity_test/application.rb', line 157

def test_framework
  @test_framework ||= setting_test_framework
end

#using_test_unit?Boolean

Return true if the application is using Test::Unit Return false otherwise

Returns:

  • (Boolean)


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

def using_test_unit?
  test_framework.instance_of?(TestUnit)
end

#verbose?Boolean

Return true if verbose mode is on Verbose mode is false as default

Returns:

  • (Boolean)


131
132
133
# File 'lib/infinity_test/application.rb', line 131

def verbose?
  config.verbose
end