versions
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
rails-3.2.18
rspec-2.14.1
parallel_tests-0.9.3
configs
.rspec
--color
--format documentation
--drb
--profile
.rspec_parallel
If installed as plugin: -I vendor/plugins/parallel_tests/lib
--color
--format documentation
--profile
when normal rspec success and not output Test unit messages
% RAILS_ENV=test bundle exec rspec
when parallel_tests rspec failed and output Test Unit messages
% RAILS_ENV=test bundle exec rake parallel:create\[4\] db:migrate parallel:prepare\[4\]
% RAILS_ENV=test bundle exec rake parallel:spec\[4\]
error
invalid option: -O
Test::Unit automatic runner.
Usage: /var/lib/jenkins/jobs/anyone.develop.spec/workspace/vendor/bundle/ruby/2.0.0/bin/rspec [options] [-- untouched arguments]
-r, --runner=RUNNER Use the given RUNNER.
(c[onsole], e[macs], x[ml])
--collector=COLLECTOR Use the given COLLECTOR.
(de[scendant], di[r], l[oad], o[bject]_space)
-n, --name=NAME Runs tests matching NAME.
(patterns may be used).
--ignore-name=NAME Ignores tests matching NAME.
(patterns may be used).
-t, --testcase=TESTCASE Runs tests in TestCases matching TESTCASE.
(patterns may be used).
--ignore-testcase=TESTCASE Ignores tests in TestCases matching TESTCASE.
(patterns may be used).
--location=LOCATION Runs tests that defined in LOCATION.
LOCATION is one of PATH:LINE, PATH or LINE
--attribute=EXPRESSION Runs tests that matches EXPRESSION.
EXPRESSION is evaluated as Ruby's expression.
Test attribute name can be used with no receiver in EXPRESSION.
EXPRESSION examples:
!slow
tag == 'important' and !slow
--[no-]priority-mode Runs some tests based on their priority.
--default-priority=PRIORITY Uses PRIORITY as default priority
(h[igh], i[mportant], l[ow], m[ust], ne[ver], no[rmal])
-I, --load-path=DIR[:DIR...] Appends directory list to $LOAD_PATH.
--color-scheme=SCHEME Use SCHEME as color scheme.
(d[efault])
--config=FILE Use YAML fomat FILE content as configuration file.
--order=ORDER Run tests in a test case in ORDER order.
(a[lphabetic], d[efined], r[andom])
--max-diff-target-string-size=SIZE
Shows diff if both expected result string size and actual result string size are less than or equal SIZE in bytes.
(1000)
-v, --verbose=[LEVEL] Set the output level (default is verbose).
(important-only, n[ormal], p[rogress], s[ilent], v[erbose])
--[no-]use-color=[auto] Uses color output
(default is auto)
--progress-row-max=MAX Uses MAX as max terminal width for progress mark
(default is auto)
--no-show-detail-immediately Shows not passed test details immediately.
(default is yes)
--output-file-descriptor=FD Outputs to file descriptor FD
-- Stop processing options so that the
remaining options will be passed to the
test.
-h, --help Display this help.
Deprecated options:
--console Console runner (use --runner).
Coverage report Rcov style generated for RSpec to /var/lib/jenkins/jobs/anyone.develop.spec/workspace/coverage/rcov
Rspecs Failed
try to
https://github.com/grosser/parallel_tests/issues/189
add spec_helper.rb
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner)
But, It did not resolve
delete spork
add
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner)
spec_helper.rb last line
resolved!
try this on your Gemfile
gem "test-unit", :require => false
or try test-unit 3.1.5.
https://github.com/test-unit/test-unit/issues/32#issuecomment-146885235
someone says about broke the application to run on Heroku. but likely the same as your problem
Related
I want to create a custom rake task with supporting multiple arguments.
When finished I want to call the rake task like:
rails conifg:load -i 5 -o "now" ...
How to create them ?
The (rubyonrails guides) says :
task :task_name, [:arg_1] => [:prerequisite_1, :prerequisite_2] do |task, args|
argument_1 = args.arg_1
end
But I dont understand it.
When finished I want to call the rake task like:
rails conifg:load -i 5 -o "now" ...
You can't, that is not how you pass arguments to Rake tasks, those arguments (-i, -o, etc) are passed to Rake itself, not to your task.
Instead, there are a few options:
Use thor which has (in my opinion) a far superior API, and allows for traditional Unix style arguments (-i, --help, etc). You can easily produce a script that would be invoked with:
thor config:load -i 5 -o "now"
Use Rake's argument system, where you would pass arguments in the form
rails config:load[5,now]
Build your own script, placed in bin. For example, bin/config can accept arbitrary arguments, and be invoked however you like. Any of the following are possible:
./bin/config load -i 5 -o now
./bin/load_config i=5 o=now
./bin/config.load 5 now
# etc
I have a rake task that I would like to be optionally given stdin, e.g. either of the following could work:
rake my_task
cat foo.txt | rake my_task
The problem is that I don't have a reliable way to check whether STDIN was given to the program. Here's my current attempt, which just hangs indeterminately:
instructions = STDIN.read.split("\n") if STDIN.tty?
I added the STDIN.tty? after reading how-can-you-check-for-stdin-input-in-a-ruby-script. It is returning true when I invoke it with rake my_task (no stdin)
You just need to invert the condition. What you want is to read stdin if it’s not a tty:
instructions = STDIN.read.split("\n") unless STDIN.tty?
I just started out with Rails, so excuse my fairly basic question. I am already noticing that the rake routes command takes a while to execute everytime I run it. I have about 20 routes for 3 controllers and it takes about 40 seconds to execute.
Is that normal? How could I speed this up?
P.S.: I am on Windows 7 with Rails 3.1.3 (set up with Rails Installer).
The rake routes task depends on the environment task which loads your Rails environment and requires thousands of Ruby files.
The startup time of a Rails environment and the corresponding rake routes execution time are very close (on my Linux on-steroids-laptop with a Rails application with ~ 50 routes):
$ time ruby -r./config/environment.rb -e ''
real 0m5.065s
user 0m4.552s
sys 0m0.456s
$ time rake routes
real 0m4.955s
user 0m4.580s
sys 0m0.344s
There is no easy way to decrease startup time as it relies on the way your interpreter requires script files : http://rhnh.net/2011/05/28/speeding-up-rails-startup-time
I came up with a solution to rake routes taking about 8 seconds to run every time. It's a simple file based cache that runs bundle exec rake routes, stores the output in a file under tmp. The filename is the md5 hash of config/routes.rb, so if you make a change and change it back, it will use the old cached file.
I put the following bash functions in an executable file I call fastroutes:
if [ ! -f config/routes.rb ]; then
echo "Not in root of rails app"
exit 1
fi
cached_routes_filename="tmp/cached_routes_$(md5 -q config/routes.rb).txt"
function cache_routes {
bundle exec rake routes > $cached_routes_filename
}
function clear_cache {
for old_file in $(ls tmp/cache_routes*.txt); do
rm $old_file
done
}
function show_cache {
cat $cached_routes_filename
}
function show_current_filename {
echo $cached_routes_filename
}
function main {
if [ ! -f $cached_routes_filename ]; then
cache_routes
fi
show_cache
}
if [[ "$1" == "-f" ]]
then
show_current_filename
elif [[ "$1" == "-r" ]]
then
rm $cached_routes_filename
cache_routes
else
main
fi
Here's a github link too.
This way, you only have to generate the routes once, and then fastroutes will used the cached values.
That seems a bit long, but do you really need to run rake routes that often? On my system, OSX Lion/Rails 3.2.0, rake routes takes ~10s.
In your Rakefile:
#Ouptut stored output of rake routes
task :fast_routes => 'tmp/routes_output' do |t|
sh 'cat', t.source
end
#Update tmp/routes_output if its older than 'config/routes.rb'
file 'tmp/routes_output' => 'config/routes.rb' do |t|
outputf = File.open(t.name, 'w')
begin
$stdout = outputf
Rake.application['routes'].invoke
ensure
outputf.close
$stdout = STDOUT
end
end
Rails environment takes a huge more amount of time to be loaded on Windows. I recommend you to give Unix a try, like Ubuntu, as Windows is the worst environment in which you can run and develop Ruby on Rails applications. But if you are just trying Rails, Windows is enough :)
When I execute %rake college:create[demo], I get the following error,
zsh: no matches found: college:create[demo]
Anybody has a solution for this?
when I execute rake -T, this is what I get when as one of the lines of the output:
rake college:create[config_name] # create a college profile
So, it is a valid command, but still zsh shows the error.
Try with:
rake college:create\[demo\]
You can also use noglob
noglob rake college:create[demo]
or just alias it in your .zshrc
alias rake='noglob rake'
zsh is trying to interpret your command as a wildcard file specication. college:create[demo] will expand to the list of existing files that match one of:
college:created
college:createe
college:createm
college:createo
This page shows some of the wildcarding that zsh performs, the specific example in this case being:
the [123] specifier, which indicates any of the characters 1, 2, or 3.
You need to escape the argument so that zsh doesn't think you're giving it a wildcard, such as with:
rake 'college:create[demo]'
The manpage for zshexpn shows all the expansions done on command lines in great detail. Search for Filename Generation for the xyzzy[demo] style generations.
If you are using rake via bundle exec or from bin/ dir add this to you .zshrc file:
alias bin/rake='noglob rake'
# or
alias rake="noglob bundled_rake
If I were to run "rspec spec/" and save the resulting output to a file named "spec_output.txt". Is there a way to have "spec_output.txt" displayed in the terminal in color?
My guess is "no". There seem to be no color codes left in the file.
I've tried:
$ rspec spec/controllers/users_controller_spec -c -o out.txt
$ rspec spec/controllers/users_controller_spec -c > out.txt
If you only want to view it later (as opposed to process it somehow), you could always use the HTML output option, which has nice formatting in addition to color.
In RSpec 3.9 you can use --tty flag to capture color codes.
$ bundle exec rspec spec/controllers/users_controller_spec --color --tty > ./tmp/rspec_results.txt
$ file ./tmp/rspec_results.txt
./tmp/rspec_results.txt: ASCII text, with escape sequences
I'm using rspec 3.12 and this works:
rspec --force-color spec/path/to/example_spec.rb > colorful.txt