I wanted to use spring instead of spork.
I installed spring and spring-commands-rspec, and after installing I created binstubs by bundle exec spring binstub --all.
When I run bin/rspec, I get only this result.
No examples found.
Finished in 0.00099 seconds
bin/rake routes gives me proper result. And bundle exec rspec tests all example I have like this.
Finished in 6.63 seconds
20 examples, 2 failures, 11 pending
Failed examples:
What am I missing? Where should I configure the place of test directories?
Try specifiying the directory:
$ bin/rspec spec/
Related
If I use spring rake, it runs my project specs to matter what rake task is specified. It just completely ignores whatever is specified at the command line and runs the specs. Here's an example:
$ spring rake routes
/Users/rsilva/.rbenv/versions/2.0.0-p353/bin/ruby -I/Users/rsilva/.rbenv/versions/2.0.0- p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.1.2/lib:/Users/rsilva/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-support-3.1.0/lib /Users/rsilva/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.1.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
Run options: exclude {:expensive=>true, :migration=>true}
# then runs all the project specs
If I don't use spring, it works fine:
$ bundle exec rake routes
Prefix Verb URI Pattern Controller#Action
# then prints out all the routes
I'm using Spring outside of my Gemfile (I did gem install spring).
Here's the versions of spring and spring-commands-rspec I'm using:
$ gem list --local | grep -P 'spring'
spring (1.1.3)
spring-commands-rspec (1.0.2)
Here's my ~/.spring.rb:
$ cat ~/.spring.rb
require 'spring-commands-rspec'
How do I get spring rake to execute the task specified?
Looks like rake is just executing the default task regardless of arguments passed. This seems to be an issue with rake 10.4.0 and spring. Try upgrading rake to 10.4.1.
https://github.com/rails/spring/issues/366
I'd like to use Cucumber via Rake for BDD in a Rails 4. I've got it installed and hooked into spring to speed up tests but they take much longer than expected to run. The tests definitively run faster when Spring is active, but there is always ~2 seconds of startup time for Cucumber even if there are no feature/scenarios to run. For example:
$ bin/spring status
Spring is not running.
$ time bin/rake cucumber
/Users/alans/.rvm/rubies/ruby-2.1.1/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
0 scenarios
0 steps
0m0.000s
bin/rake cucumber 0.08s user 0.02s system 3% cpu 3.463 total
$ bin/spring status
Spring is running:
64383 spring server | cucumber_test | started 48 secs ago
64384 spring app | cucumber_test | started 48 secs ago | test mode
$ time bin/rake cucumber
/Users/alans/.rvm/rubies/ruby-2.1.1/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
0 scenarios
0 steps
0m0.000s
bin/rake cucumber 0.08s user 0.02s system 4% cpu 2.098 total
Using bin/rake for the run is what's defined in the Spring Readme. Running spring without rake produces the faster expected times.
$ time spring cucumber
Using the default profile...
0 scenarios
0 steps
0m0.000s
spring cucumber 0.06s user 0.01s system 13% cpu 0.537 total
The Question
How can I setup Cucumber, Spring and Rake so that tests run as quickly with Rake as without?
Further Details
My environment is an RVM install of ruby-2.1.1 and rails 4.1.1 on a Mac with an SSD running 10.9.3.
Here's what I'm doing:
Create an app with
rails new cucumber_test -T
Update the gem file with the following:
group :development, :test do
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'rspec-rails'
gem 'spring'
gem 'spring-commands-cucumber'
end
Then running:
bundle install
(I also tried leaving the default listing for spring in just the :development environment but that didn't speed things up either.)
Run the Cucumber generator:
rails g cucumber:install
Update the Spring binstubs:
bundle exec spring binstub --all
Which returns:
* bin/rake: spring already present
* bin/cucumber: generated with spring
* bin/rails: spring already present
This is where I run the time tests. When Spring is stopped, Cucumber consistently takes longer to run. Even with Spring running it seems there is always a 2 second overhead before the test suite actually kicks off when using Rake. That's what I'm trying to eliminate.
I upgraded rails to 4.1.0 & installed gem "spring"
After it, I patched bundle exec spring binstub --all. Now, all my bin/* includes
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
But, if I run, saying time spring rake -T & time rake -T times 1 second & 3 seconds! It seems that spring not used by default in my application. What's going wrong? It's bad thing that I need to write annoying spring ..command.. before any rake task, rails server or rspec. What I need to do to avoid spring command with spring worked by default?
You don't need to prepend spring everytime. I'm not sure why you're getting those numbers but try the following.
# make sure that spring server is stopped
>> spring stop
# take note of the time here
>> time bin/rake routes
# start spring server
>> spring
# test routes again
>> time bin/rake routes
The second bin/rake routes should be very fast. In one of our apps, without spring, it takes 8 seconds to show the routes. With spring, it's less than a second.
For rspec, you need to install an additional gem for that. Look at the additional commands section of the spring gem
I'm trying to pipe mail from postfix to a rails tasks. I've got this working successfully when just piping to a vanilla ruby script, but when switching to a rails task I get the following error in the mail.log from Postfix:
(Command died with status 1: "/usr/local/bin/rake". Command output: /usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in to_specs': Could not find rake (>= 0) amongst [] (Gem::LoadError) from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:into_spec' from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in gem' from /usr/local/bin/rake:22:in' )
Here is the piping line from master.cf
email-task unix - n n - 2 pipe
flags=Xhq user=appuser directory=/home/myapp/application/ argv=/usr/local/bin/rake RAILS_ENV=production myapp:process_email
Running the command which rake returns /usr/local/bin/rake so I have verified I have the correct rake path.
I've tried setting ENV['PATH'] inside of the .rake file to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games and I've also tried cd'ing to the rails app directory in the pipe command but still causes the same error. I've done bundle install and update etc.
Any help is greatly appreciated...thank you!
UPDATE
I tried using bundle exec rake etc as suggested but am now getting this error:
Command died with status 127: "/usr/local/bin/bundle". Command output: bundler: command not found: rake Install missing gem executables with bundle install
I've tried adding gem 'rake' to the Gemfile as well. I'm assuming bundler can't find the Gemfile?
UPDATE (FIXED)
So the command that finally worked was the following:
email-task unix - n n - 2 pipe
flags=Xhq user=appuser directory=/home/myapp/application/ argv=/usr/local/bin/bundle exec /usr/local/bin/rake RAILS_ENV=production mytask
It was a combination of errors on my part.
Full paths need to be used for bundle and rake
app name is not needed in the task param for rake since the directory is being selected before executing
A side issue: an old version of ruby was being used which caused an unrelated gem error after executing the postfix pipe
Appreciate the help everyone.
I think your on the wrong track, it's not the system that can't find rake it's your rubygems. Instead of running rake as your command, try running bundle passing whatever you need to in order for it to basically be bundle exec rake...etc
Update
Based on your new information, it would seem that the rake gem is not installed in your app. Run bundle show rake
Assuming it's not there, I'm wondering why. Did you ship your app with packaged gems or something? Basically, did you not run bundle install in your deployed app?
What is the difference between doing:
bundle exec rake
and
rake
I see people doing both, I never do bundle before my commands, curious what the reason for it is?
bundle exec executes a command in the context of the bundle.
This command executes the command, making all gems specified in the Gemfile available to require in Ruby programs.
Very useful when you have many applications with different versions of gems used
in them.
Please see docs for more information: http://gembundler.com/man/bundle-exec.1.html
bundle exec runs the command after it in the environment of Bundler. So say you had rake 0.9 in you Gemfile, but rake 10 installed in RubyGems.bundle exec rake will run rake 0.9 instead of rake 10.