Class: SauronTemplate
- Inherits:
-
Object
- Object
- SauronTemplate
- Defined in:
- lib/sauron/sauron_template.rb
Instance Attribute Summary collapse
-
#framework ⇒ Object
Returns the value of attribute framework.
-
#hydra ⇒ Object
Returns the value of attribute hydra.
-
#workers ⇒ Object
Returns the value of attribute workers.
Instance Method Summary collapse
- #all_tests ⇒ Object
- #config_file ⇒ Object
- #functional_tests ⇒ Object
- #helper_tests ⇒ Object
-
#initialize ⇒ SauronTemplate
constructor
A new instance of SauronTemplate.
- #message(body) ⇒ Object
- #routing_tests ⇒ Object
- #run_all_tests ⇒ Object
- #run_multiple_tests(*files) ⇒ Object
- #run_pattern_tests(prefix, pattern, suffix) ⇒ Object
- #run_routing_tests ⇒ Object
- #run_single_test(file) ⇒ Object
- #set_hydra ⇒ Object
- #setup_databases ⇒ Object
- #startup ⇒ Object
- #unit_tests ⇒ Object
- #view_tests(controller = :all) ⇒ Object
Constructor Details
#initialize ⇒ SauronTemplate
Returns a new instance of SauronTemplate.
7 8 9 10 11 12 13 14 |
# File 'lib/sauron/sauron_template.rb', line 7 def initialize if File.exists? config_file config = YAML::load(ERB.new(IO.read(config_file)).result) self.framework = config[:framework] self.workers = config[:workers] end end |
Instance Attribute Details
#framework ⇒ Object
Returns the value of attribute framework.
5 6 7 |
# File 'lib/sauron/sauron_template.rb', line 5 def framework @framework end |
#hydra ⇒ Object
Returns the value of attribute hydra.
5 6 7 |
# File 'lib/sauron/sauron_template.rb', line 5 def hydra @hydra end |
#workers ⇒ Object
Returns the value of attribute workers.
5 6 7 |
# File 'lib/sauron/sauron_template.rb', line 5 def workers @workers end |
Instance Method Details
#all_tests ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/sauron/sauron_template.rb', line 126 def all_tests case framework when 'testunit' Dir.glob('test/**/*_test.rb') when 'rspec' Dir.glob('spec/**/*_spec.rb') end end |
#config_file ⇒ Object
16 17 18 |
# File 'lib/sauron/sauron_template.rb', line 16 def config_file 'config/sauron.yml' end |
#functional_tests ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/sauron/sauron_template.rb', line 95 def functional_tests case framework when 'testunit' Dir.glob('test/functional/*_test.rb') when 'rspec' Dir.glob('spec/controllers/*_spec.rb') end end |
#helper_tests ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/sauron/sauron_template.rb', line 86 def helper_tests case framework when 'testunit' Dir.glob('test/unit/helpers/*_test.rb') when 'rspec' Dir.glob('spec/helpers/*_spec.rb') end end |
#message(body) ⇒ Object
135 136 137 138 |
# File 'lib/sauron/sauron_template.rb', line 135 def body system 'clear' puts body end |
#routing_tests ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/sauron/sauron_template.rb', line 117 def routing_tests case framework when 'testunit' Dir.glob('test/unit/rout{es,ing}_test.rb') when 'rspec' Dir.glob('spec/models/rout{es,ing}_spec.rb') end end |
#run_all_tests ⇒ Object
72 73 74 75 |
# File 'lib/sauron/sauron_template.rb', line 72 def run_all_tests "running all tests" run_multiple_tests all_tests end |
#run_multiple_tests(*files) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sauron/sauron_template.rb', line 55 def run_multiple_tests *files joined_files = files.join(',') "running #{files.first.size} tests: #{joined_files}" if hydra system "time rake hydra:sauron RAILS_ENV=test FILE_LIST=#{joined_files} SAURON_WORKERS=#{workers}" else case framework when 'testunit' system "time ruby -I.:lib:test -rubygems -e \"%w[#{files.join(' ')}].each {|f| require f}\"" when 'rspec' system "time ruby script/spec -O spec/spec.opts #{files.join(' ')}" end end end |
#run_pattern_tests(prefix, pattern, suffix) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sauron/sauron_template.rb', line 44 def run_pattern_tests prefix, pattern, suffix files = [] elements = pattern.split(/_/) begin files << Dir.glob("#{prefix}#{elements.join('_')}#{suffix}") unless elements.empty? end while elements.shift files.size == 1 ? run_single_test(files.first) : run_multiple_tests(files) end |
#run_routing_tests ⇒ Object
28 29 30 31 |
# File 'lib/sauron/sauron_template.rb', line 28 def run_routing_tests "running routing tests" run_multiple_tests routing_tests end |
#run_single_test(file) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sauron/sauron_template.rb', line 33 def run_single_test file "running #{file}" case framework when 'testunit' system "time ruby -I.:lib:test -rubygems -e \"require '#{file}'\"" when 'rspec' system "time ruby script/spec -O spec/spec.opts #{file}" end end |
#set_hydra ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/sauron/sauron_template.rb', line 20 def set_hydra if self.hydra = !!(`rake -T hydra:sauron` =~ /hydra:sauron/) "Using hydra to run multiple tests in parallel" else "You don't have hydra properly setup. All tests will be run in single-threaded mode." end end |
#setup_databases ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/sauron/sauron_template.rb', line 140 def setup_databases print "setting up #{workers} workers and their databases (you can change in config/sauron.yml)" STDOUT.flush # setup each database # workers.times do |i| print '.' STDOUT.flush hydra_worker_id = (i == 0 ? '' : i) test_env_number = (i == 0 ? '' : i + 1) `rake db:reset RAILS_ENV=test HYDRA_WORKER_ID=#{hydra_worker_id} TEST_ENV_NUMBER=#{test_env_number}` end end |
#startup ⇒ Object
156 157 158 159 160 |
# File 'lib/sauron/sauron_template.rb', line 156 def startup set_hydra setup_databases run_all_tests end |
#unit_tests ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/sauron/sauron_template.rb', line 77 def unit_tests case framework when 'testunit' Dir.glob('test/unit/*_test.rb') when 'rspec' Dir.glob('spec/models/*_spec.rb') end end |
#view_tests(controller = :all) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/sauron/sauron_template.rb', line 104 def view_tests controller = :all case framework when 'testunit' [] when 'rspec' if controller == :all Dir.glob('spec/views/**/*_spec.rb') else Dir.glob('spec/views/#{controller}/*_spec.rb') end end end |