How to enable colors with rspec when using JRuby or bundle exec?
Adding --tty
to the call fixes the problem for me:
jruby -S bundle exec rspec --tty --color spec/foo_spec.rb
The option tells RSpec that the output is not written to a file (in which case you wouldn't want colorized output), but send to another process instead.
How do I get the color from the backticks command in ruby?
From reading the code it looks like RSpec calls IO#isatty on the output stream to decide whether or not to colorize the output. The backquote method must work differently from system
in this respect.
EDIT
This works if you add the option --tty
to the rspec command:
`rspec --color --tty file_spec.rb`
as mentioned in this SO question.
How do I keep the *colorized* output result of a command when printing the result of a command in Ruby?
Take a look at this and this questions, they are about just the same thing but with rspec
instead of cucumber
.
How do I get colour with Windows command prompt using RSpec in Ruby?
UPDATE:
Win32Console no longer works with rspec. ANSICON recommended.
https://github.com/rspec/rspec-rails/issues/487#issuecomment-3556806
Using guard with JRuby on Windows fails
I think it's a bundler
bug as I get the same error if I run:
bundle exec rspec spec
I manage to make it work commenting and adding some code to guard-rspec
source file.
Open file:
C:\jruby-1.6.7\lib\ruby\gems\1.8\gems\guard-rspec-0.6.0\lib\guard\rspec\runner.rb
Obs: Note that this path might be diferent on you machine. Anyway, just go to the source of the guard-rspec
gem and open the runner.rb
file.
And change the rspec_command
to this:
def rspec_command(paths, options={})
warn_deprectation(options)
cmd_parts = []
cmd_parts << "rvm #{options[:rvm].join(',')} exec" if options[:rvm].is_a?(Array)
cmd_parts << "bundle exec" if (bundler? && options[:binstubs] == true && options[:bundler] != false) || (bundler? && options[:bundler] != false)
cmd_parts << "'"
cmd_parts << rspec_exec(options)
cmd_parts << options[:cli] if options[:cli]
cmd_parts << "-f progress" if options[:cli].nil? || !options[:cli].split(/[\s=]/).any? { |w| %w[-f --format].include?(w) }
#cmd_parts << "-r #{File.dirname(__FILE__)}/formatters/notification_#{rspec_class.downcase}.rb -f Guard::RSpec::Formatter::Notification#{rspec_class}#{rspec_version == 1 ? ":" : " --out "}/dev/null" if options[:notification] != false
cmd_parts << "--failure-exit-code #{failure_exit_code}" if failure_exit_code_supported?(options)
cmd_parts << paths.join(' ')
cmd_parts << "'"
cmd_parts.join(' ')
end
The changes I made:
1. commented on of the lines
2. Added 2 code line to add "quotes" to the string builder.
It works here, so it should work on your machine as well.
I open an issue on bundler https://github.com/carlhuda/bundler/issues/1689 for the issue.
Related Topics
What Does This Mean in Ruby Language
Native Threads in Ruby 1.9.1, Whats in It for Me
How to Listen to Stdin Input Without Pausing My Script
Multipart Response in Ruby/Rack
Ruby Regex to Capture Everything Between Two Strings (Inclusive)
Show Markers on Google Maps Dynamically -Rails 3.2
How to Get a Listing of Only Files Using Dir.Glob
Using Fork in Windows with Ruby
Ruby: Automatically Set Instance Variable as Method Argument
Finding the Date for a Given Week Number
Bundler Could Not Find Compatible Versions for Gem "Bundler": in Gemfile:
Ruby + Tk Command Binding - Scope Issue
Exclude Draft Articles from Solr Index with Sunspot
How to Create a Custom Method for the Rails Console
Activerecord_Postgis_Adapter: Undefined Method 'Point' for Nil:Nilclass