Class: HuginnAgent::SpecRunner
- Inherits:
-
Object
- Object
- HuginnAgent::SpecRunner
- Defined in:
- lib/huginn_agent/spec_runner.rb
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
Instance Method Summary collapse
- #bundle ⇒ Object
- #clone ⇒ Object
- #database ⇒ Object
-
#initialize ⇒ SpecRunner
constructor
A new instance of SpecRunner.
- #reset ⇒ Object
- #shell_out(command, message = nil, streaming_output = false) ⇒ Object
- #spec ⇒ Object
Constructor Details
#initialize ⇒ SpecRunner
Returns a new instance of SpecRunner.
7 8 9 10 |
# File 'lib/huginn_agent/spec_runner.rb', line 7 def initialize @gem_name = File.basename(Dir['*.gemspec'].first, '.gemspec') $stdout.sync = true end |
Instance Attribute Details
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
5 6 7 |
# File 'lib/huginn_agent/spec_runner.rb', line 5 def gem_name @gem_name end |
Instance Method Details
#bundle ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/huginn_agent/spec_runner.rb', line 24 def bundle if File.exists?('.env') shell_out "cp .env spec/huginn" end Dir.chdir('spec/huginn') do shell_out "bundle install --without development production -j 4", 'Installing ruby gems ...' end end |
#clone ⇒ Object
12 13 14 15 16 |
# File 'lib/huginn_agent/spec_runner.rb', line 12 def clone unless File.exists?('spec/huginn/.git') shell_out "git clone #{HuginnAgent.remote} -b #{HuginnAgent.branch} spec/huginn", 'Cloning huginn source ...' end end |
#database ⇒ Object
34 35 36 37 38 |
# File 'lib/huginn_agent/spec_runner.rb', line 34 def database Dir.chdir('spec/huginn') do shell_out('bundle exec rake db:create db:migrate', 'Creating database ...') end end |
#reset ⇒ Object
18 19 20 21 22 |
# File 'lib/huginn_agent/spec_runner.rb', line 18 def reset Dir.chdir('spec/huginn') do shell_out "git fetch && git reset --hard origin/#{HuginnAgent.branch}", 'Resetting Huginn source ...' end end |
#shell_out(command, message = nil, streaming_output = false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/huginn_agent/spec_runner.rb', line 46 def shell_out(command, = nil, streaming_output = false) print if (status, output) = Bundler.with_clean_env do ENV['ADDITIONAL_GEMS'] = "#{gem_name}(path: ../../)" ENV['RAILS_ENV'] = 'test' HuginnAgent::Helper.open3(command, streaming_output) end if status == 0 puts "\e[32m [OK]\e[0m" if else puts "\e[31m [FAIL]\e[0m" if puts "Tried executing '#{command}'" puts output fail end end |
#spec ⇒ Object
40 41 42 43 44 |
# File 'lib/huginn_agent/spec_runner.rb', line 40 def spec Dir.chdir('spec/huginn') do shell_out "bundle exec rspec -r #{File.join(__dir__, 'patches/coverage.rb')} --pattern ../*_spec.rb,../{[!huginn/]}**/*_spec.rb", 'Running specs ...', true end end |