Rake file with Jenkins (Cucumber, watir-webdriver) - ruby

I've started with watir and cucumber a while ago and have been trying to run my project with Jenkins. I have a watir Project (watir,cucumber) in C:\project_name. I have rake file in the project also and when I run it in CMD everything goes ok and tests are succesfully executed --> C:\project_name>rake
Rakefile I'm running looks like this.
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
t.profile = 'default'
end
task :default => :features
I have tried to execute Rake file with Jenkins but unable to make it work. So far what I have done with Jenkins (Running in localhost:8080)
1) Plugins installed eg. cucumber-reports, Jenkins Rake plugin
2) Tried to add New job --> Build a free-style software project
I really don't have idea how to make Rake file to work with Jenkins. I was hoping to get these nice reports (cucumber-reporting) available through Jenkins.
If someone can help me with this it would be more than perfect.

Related

SimpleCov code coverage comparize with last build in Jenkins

I have situation where I want to compare code coverage of last Jenkins build from current Jenkins build so if current Jenkins build code coverage is low then last one , build should unstable or failed
Is that possible with any Jenkins plugin or do I need to do some stuff with SimpleCov?
You can use the RUbyMetrics Jenkins plugin: https://wiki.jenkins.io/display/JENKINS/RubyMetrics+plugin
along with with simplecov-json and simplecov-rcov gems.
So you need to add this to your rspec_helper:
require 'simplecov'
require 'simplecov-json'
require 'simplecov-rcov'
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::RcovFormatter
]
SimpleCov.start

middleman-deploy pushes from root instead of build dir

Background
I'm using middleman-deploy to deploy to a github page for an organization.
It's my understanding that the middleman build dir (/build in this case) is what will get deployed to github. That is, the directory that contains files after a bundle exec middleman build, including the index.html file.
What I'm getting in my github repo is the root of the project. I'm using bundle exec middleman deploy --build-before
config.rb
activate :deploy do |deploy|
deploy.method = :git
deploy.remote = 'https://github.com/FiercePunchStudios/fiercepunchstudios.github.io.git'
deploy.branch = 'master'
end
Question
How do I deploy my middleman site to a github organization page, using middleman-deploy?
Thanks to #robinbortlik, there's a handy little extension right on the github issue. https://github.com/middleman-contrib/middleman-deploy/issues/114#issuecomment-168139237
#lib/build_cleaner.rb
class BuildCleaner < Middleman::Extension
def initialize(app, options_hash={}, &block)
super
FileUtils.rm_rf app.config[:build_dir]
end
end
::Middleman::Extensions.register(:build_cleaner, BuildCleaner)
#config.rb
require_relative "./lib/build_cleaner"
configure :build do
activate :build_cleaner
end
This deletes the build directory before the build action. Now you can just do a single command, like bundle exec middleman deploy --build-before
It's still not something I'd consider a fix, because I'd like to not have to add boilerplate to every middleman project I start. However, it's a convenient workaround that smooths out the deploy process for now.

How to run a rake task depending on environment?

I'm trying to export Mixpanel raw data, as documented here
https://mixpanel.com/docs/api-documentation/exporting-raw-data-you-inserted-into-mixpanel
As the Mixpanel team didn't bother to just provide a script doing this, a kind soul made this Rake task
https://gist.github.com/wongpeiyi/3217208
I figured out that it needs to go into a file named "Rakefile", and executed with
$ rake mixpanel:pull
However, that gives
rake aborted!
Don't know how to build task 'environment'
Tasks: TOP => mixpanel:pull
How can this task be run?
Thanks!
The rake task was problably written to be included in a rails project. You can just remove the dependency on the :environment task.
So change the task line to
task :pull do
that should do the trick. It could be possible that some gems are missing (that is what the :environment task does: it loads the rails environment).

Using SimpleCov in a Ruby Project

I am trying to use the simplecov gem in a Ruby project. However I have failed miserably. Here is what I've done until now.
My project structure is:
ProjectFolder
- lib
- test
I have my tests in test and source code in lib. I have created a test_helper.rb in the test directory and added the following.
require 'simplecov'
SimpleCov.start
Then I put `require 'test/test_helper.rb' in every test file. What happened was it sometimes created some report, and sometimes didn't. And when it did it was inconsistent.
All the tutorials I found was for Rails so I turn to StackOverflow once more, to show me the way.
Rcov/SimpleCov will only report the coverage of the tests ran.
For a full coverage report, you must ensure that the full test suite is ran as the last test, to build a full coverage report.
You will also want to make sure it is the first require in your test_helper.rb file.
From the documentation:
Note: If SimpleCov starts after your application code is already
loaded (via require), it won't be able to track your files and their
coverage! The SimpleCov.start must be issued before any of your
application code is required!

How to get Hudson to see rcov results?

I am currently working to integrate rcov with our Hudson server.
I am able to run rcov via rake and get the results with out issue (see rake file below). When I run things via Hudson - calling the rake task - the tests with coverage are clearly generated and displayed in the console.
But at almost the end, the following shows up in the console:
** Execute test:coverage
Recording test results
No test report files were found. Configuration error?
Build wasn't successful, skipping rcov coverage report
Finished: FAILURE
Rake task
desc 'Aggregate code coverage for unit, functional and integration tests'
task :coverage => "test:coverage:clean"
%w[unit functional].each do |target|
namespace :coverage do
Rcov::RcovTask.new(target) do |t|
t.libs << "test"
t.test_files = FileList["test/#{target}/*_test.rb"]
t.output_dir = "coverage"
t.verbose = true
t.rcov_opts << '--rails --aggregate coverage.data'
end
end
task :coverage => "test:coverage:#{target}"
end
Going to coverage/ I see output file. The coverage.data file is present as well.
Any thoughts on what might be going wrong here? Am I missing something blindingly obvious?
Hudson will not pull the coverage results if the build has failed further up the chain. I ran into this issue when one test was failing, and could not figure out why coverage was not being reported.

Resources