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



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

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



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

def add_heuristics!
  app_framework.add_heuristics!
end

#after_callbackObject

Return the block object setting in the config file



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

def after_callback
  config.after_callback
end

#after_each_ruby_callbackObject

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



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

def after_each_ruby_callback
  config.after_each_ruby_callback
end

#all_test_filesObject

Return all the tests files in the User application



280
281
282
# File 'lib/infinity_test/application.rb', line 280

def all_test_files
  test_framework.all_files
end

#app_frameworkObject

Return a instance of the app framework class



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

def app_framework
  @app_framework ||= setting_app_framework
end

#before_callbackObject

Return the block object setting in the config file



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

def before_callback
  config.before_callback
end

#before_each_ruby_callbackObject

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



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

def before_each_ruby_callback
  config.before_each_ruby_callback
end

#construct_commandsObject

Contruct all the commands for the test framework



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

def construct_commands
  test_framework.construct_commands
end

#failure_imageObject

Return the failure image to show in the notifications



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

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


252
253
254
255
256
257
258
259
# File 'lib/infinity_test/application.rb', line 252

def files_to_run!(options)
  return options.to_s if options.is_a?(MatchData)
  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

#have_gemfile?Boolean

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

Returns:

  • (Boolean)


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

def have_gemfile?
  File.exist?(gemfile)
end

#heuristicsObject

Return all the Heuristics of the application



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

def heuristics
  config.instance_variable_get(:@heuristics)
end

#heuristics_users_high_priority!Object



179
180
181
# File 'lib/infinity_test/application.rb', line 179

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



231
232
233
234
235
236
237
238
239
# File 'lib/infinity_test/application.rb', line 231

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



203
204
205
# File 'lib/infinity_test/application.rb', line 203

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



209
210
211
212
213
214
215
216
217
# File 'lib/infinity_test/application.rb', line 209

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’



223
224
225
# File 'lib/infinity_test/application.rb', line 223

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

#pending_imageObject

Return the pending image to show in the notifications



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

def pending_image
  config.pending_image
end

#rubiesObject

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



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

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



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/infinity_test/application.rb', line 187

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



287
288
289
290
291
292
# File 'lib/infinity_test/application.rb', line 287

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



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

def run_global_commands!
  run!(global_commands)
end

#say_the_ruby_version_and_run_the_command!(ruby_version, command) ⇒ Object



294
295
296
297
298
# File 'lib/infinity_test/application.rb', line 294

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



273
274
275
276
# File 'lib/infinity_test/application.rb', line 273

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



263
264
265
266
267
268
269
# File 'lib/infinity_test/application.rb', line 263

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

#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
# File 'lib/infinity_test/application.rb', line 49

def setup!(options)
  config.use(
     :rubies => (options[:rubies] || rubies),
     :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)


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

def skip_bundler?
  config.skip_bundler?
end

#sucess_imageObject

Return the sucess image to show in the notifications



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

def sucess_image
  config.sucess_image
end

#test_frameworkObject

Return a instance of the test framework class



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

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)


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

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)


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

def verbose?
  config.verbose
end