Jekyll plugin hook on calling jekyll clean - ruby

I would like to make plugin with hook that will be called every time jekyll clean --trace is run.
How can I achieve hook like this ?

Related

task in Capistrano 3 cannot find RVM

I have been using Capistrano 3 to deploy a PHP app for several months and it works great. Recently, we decided to start using Sass for stylesheets and I am now trying to deploy these changes.
I am trying to write a task that runs after the rest of the deploy stuff is finished that converts a scss file to css using the Sass gem.
namespace :deploy do
after :finished, :assets do
on roles(:app), in: :sequence, wait: 5 do
within release_path do
# process sass files to css
execute "sass #{release_path}/styles/test.scss #{release_path}/styles/test.css"
end
end
end
end
I am using RVM on the server and have the sass gem installed in a specific gemset. There is also an .rvmrc file in the project root that loads the correct gemset when you cd into the 'current' directory that capistrano creates.
When I deploy, it fails on my new task saying that it cannot find sass.
stderr: bash: sass: command not found
I can log into the server as the same user that is used to deploy with Capistrano and cd into the 'current' directory and run the same command in the task (substituting the #{release_path} with actual path) and it works fine.
Things I have tried:
rewriting the execute command with the following:
rvm use 2.1.5#deployer && sass #{release_path}/styles/test.scss #{release_path}/styles/test.css
writing a bash script accessible by the deployer user that loads the gemset then runs the sass command (works when I run the new script while logged into the sever in any directory, does not work when called from the capistrano task)
using the capistrano-rvm plugin (adding to Gemfile, requiring in Capfile) to set the RVM gemset - hoping that it would load the gemset before running any commands.
I have used Capistrano many times for deploying Rails apps and always use the asset plugin that handles precompiling and whatnot... This is the first project that I have used for deploying a PHP app and maybe the first time I have tried to manually run a capistrano task that uses a rubygem installed on the server with RVM.
Is it possible to run a task that depends on a specific gem/gemset... without using the default rails plugins?
Any help is appreciated.
Thanks,
JD
figured this one out by requiring the capistrano/bundler command, just to see how capistrano runs bundle by default... copied the bundler command that was logged during a deploy, then modified it to work for what I was trying to do and finally removed the bundler plugin as I do not actually need the deploy to bundle anything.
without using any capistrano plugins, you can preface the capistrano task execute command with the location of the gemset like so:
after :finished, :assets do
on roles(:app), in: :sequence, wait: 5 do
within release_path do
execute "~/.rvm/bin/rvm ruby-2.1.5#deployer do sass #{release_path}/styles/sass/screen.scss #{release_path}/styles/screen.css"
end
end
end
The key difference is the following snippet prefaces the actual command I was trying initially:
~/.rvm/bin/rvm ruby-2.1.5#deployer do ....
Obviously, you could use whatever command requiring the gemset specified that you want (instead of the sass command I am using).

On Travis how do I modify tests to use minitest instead of rspec?

The link for ask question on Travis dot com sent me here. My tests fail because I'm using minitest in my gem but travis uses rspec. Is there a way to get travis to do that also? Of course I can always modify my tests to use rspec but I'm not sure how to get tests or spec from my structure of my tests. They all have assert_equal which is not recognized by respec as a valid method. Is there a common way to make either test work with the same *_spec.rb files?
This is another option to run your test in your .travis.yml:
script:
- bin/rails test
Remeber to install the gems before run the scripts.
I found in the docs that it is possible to define custom commands for running tests (rather than the default bundle exec rake test) by placing these lines in .travis.yml
script:
- bundle exec rake build
- bundle exec rake builddoc

How to run Cucumber tests from inside a project to run on another project

I want to run my command line tool in a project against another project to analyze Cucumber tests. Both projects have their own gemsets.
When I execute Cucumber pointing to the other project, then it tries to execute using my gemset/configuration, then it fails.
How can I "change scope/context" to make Cucumber run in the other project folder (and use its own Gemfile and configuration)?
Something like the following should work:
Bundler.with_clean_env do
system("cd other/project; bundle exec cucumber")
end
The "quick and dirty" solution was make a system call, then entering into the main project directory; run bundle install; then cucumber features/
system("cd other/project && bundle install && bundle exec cucumber features/")

How to build and run a Ruby command-line tool found on github?

Hi cloned a simple app ( https://github.com/cfx/twix) on github that allows me to send Twitter messages from the console, but I'm not sure how to run it.
I now have a folder in my users/name director called Twix. Inside twix, I have these folders created by the app.
README Rakefile bin lib test
The readme doesn't provide a lot of instruction to get things started. It just tells you what to do after the program's running (see below).
Questions: What command do I use to get this started? What folder do I need to be in?
The README
Twix 0.0.1
Simple twitter client for console
Keys:
q - quit
t - write new message
If you want to post your twit, finish you message with !SEND
If you want abort and back to your feed, finish your message with !EXIT
new features soon
This program is packaged as a gem. The following command will install the gem (run it in the Twix directory):
rake package && gem install pkg/twix-0.0.1.gem
You can now run the program from anywhere with the twix command.
Edit
The first thing I saw in the repository was the Rakefile, meaning there were some rake tasks defined. When you find yourself in this case, running rake -T is your best bet as it will show you the rake tasks available. Its output was the following:
(in /home/benoit/code/clones/twix)
rake clobber_package # Remove package products
rake gem # Build the gem file twix-0.0.1.gem
rake package # Build all the packages
rake repackage # Force a rebuild of the package files
I picked the command that would be the most likely to build the gem: the package one. I guess the gem task would have worked as well.
Running rake package gave me the following output:
(in /home/benoit/code/clones/twix)
mkdir -p pkg
WARNING: no homepage specified
Successfully built RubyGem
Name: twix
Version: 0.0.1
File: twix-0.0.1.gem
mv twix-0.0.1.gem pkg/twix-0.0.1.gem
All that was left was to install the pkg/twix-0.0.1.gem created by the previous command:
gem install pkg/twix-0.0.1.gem
There's another case you could have encountered: the presence of a twix.gemspec in the root directory of the application. In this case, running:
gem build twix.gemspec
would have built the gem, the installation step remains the same.
ruby ./bin/twix
or
ruby -I lib ./bin/twix

Execute tests for another app from a rake file

I'm trying to execute cucumber tests for a project within a rake file in another project.
Currently I am trying this:
system "cd /path/to/project;rvm use --create 1.9.2-p290#test; cucumber features/test.feature"
This works for the cd, and the rvm seems to work if I run which ruby after the rvm use... but the problem is that the cucumber gem seems to be called from the current folder (not the app to test folder).
The error I get is:
cucumber is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
It seems to be using the local gemset version of cucumber rather than the #test gemset.
Any thoughts on this?
Or is there a better way to run cucumber tests for another project that relies on rvm & a different bundle?
I've also been trying to do exactly the same thing; run an application's tests (or any rake task) from inside another 'control' application.
Reason: (just so I don't get served with a "why on earth?")
I am trying to build an application (rather like cruisecontrol.rb ) which can monitor, schedule and review the specs for a set of apps.
After some digging around in cruisecontrol's source I found that Bundler provides a solution;
Bundler.with_clean_env do
system "rake spec"
end
see line56 of https://github.com/thoughtworks/cruisecontrol.rb/blob/master/lib/platform.rb
That steps out of the bundle and the command is run without the control app's gems.
BUT as is most likely, the command uses bundle exec then this stops working.
Bundler.with_clean_env { system "bundle exec rake spec" }
And you are right back to the exact same problem. This is caused by some bundler variables still existing and being inherited by the sub-shell. Full (very good) explanation here.
The solution is to change the with_clean_env method on bundler like this;
BUNDLER_VARS = %w(BUNDLE_GEMFILE RUBYOPT BUNDLE_BIN_PATH)
module Bundler
def self.with_clean_env &blk
bundled_env = ENV.to_hash
BUNDLER_VARS.each{ |var| ENV.delete(var) }
yield
ensure
ENV.replace(bundled_env.to_hash)
end
end
above code from here
I put that in the environment.rb of my control application (it should probably be in a initializer?) and now I can run the specs of another app from within the control app.
#in control app
result = nil
Dir.chdir(test_app_path) #move into test app
Bundler.with_clean_env { result = `bundle exec rake spec` } #run test apps specs
puts result #display result inside control app
Changing the ; in your script to && seems to work.

Resources