padrino / padrino-framework

Padrino is a full-stack ruby framework built upon Sinatra.
http://www.padrinorb.com
MIT License
3.37k stars 509 forks source link

Padrino has a problem with Rake when using RSpec #514

Closed yuya-takeyama closed 13 years ago

yuya-takeyama commented 13 years ago

Hi. I'm enjoying my development with Padrino thank you.

Using RSpec as testing framework, rake command (not "padrino rake") seems to have a problem. And it causes "heroku rake" failure.

I'm using below.

Appears by the following.

$ padrino g project test-project -t rspec -b
$ cd test-project

Save below as "Rakefile".

require File.dirname(__FILE__) + '/config/boot.rb'
require 'thor'
require 'padrino-core/cli/rake'

PadrinoTasks.init

padrino rake

$ padrino rake -T
=> Executing Rake -T ...
rake routes[query]    # Displays a listing of the named routes within a project, optionally only those matched by [query]
rake routes:app[app]  # Displays a listing of the named routes a given app [app]
rake secret           # Generate a secret key
rake seed             # Load the seed data from db/seeds.rb
rake spec             # Run complete application spec suite

Normal rake

$ rake -T
(in /Users/yuya/dev/ruby/test-project)
=> Located unlocked Gemfile for development
rake aborted!
no such file to load -- rspec/core/rake_task
/Users/yuya/.rvm/gems/ruby-1.9.2-head/gems/padrino-core-0.9.26/lib/padrino-core/cli/rake.rb:21:in `load'
(See full trace by running task with --trace)
yuya-takeyama commented 13 years ago

I solved this problem like this.

diff --git a/Gemfile b/Gemfile
index fb1a83e..204abea 100644
--- a/Gemfile
+++ b/Gemfile
@@ -14,7 +14,7 @@ gem 'mongoid', "2.0.0"
 gem 'bson_ext', :require => "mongo"

 # Test requirements
-gem 'rspec', :group => "test"
+gem 'rspec'
 gem 'rack-test', :require => "rack/test", :group => "test"

Now i can execute "rake" and "heroku rake" too. Thank you.

nesquena commented 13 years ago

Interesting, thanks for the note. Should we make this change in the rspec component? Looks like you just changed

gem 'rspec', :group => "test"

to

gem 'rspec'

Is that right?

yuya-takeyama commented 13 years ago

Yes. That is all.

DAddYE commented 13 years ago

haaaaaaaaaaa found!

You forgot to set the environment:

$ PADRINO_ENV=test rake spec

will work like a charm!

remember that when you use :group => 'some' in Gemfile you need to set the PADRINO_ENV=some for handle it.

nesquena commented 13 years ago

That seems to be a bit confusing, shouldn't we remove that group? Nobody knows to set that env in front and they shouldn't need to IMO.

DAddYE commented 13 years ago

Groups are useful because you prevent to install (ex: production) tests stuff.

Generally is a great thing use PADRINO_ENV / RACK_ENV because you are sure for example to use the correct database ... in this case the test_database

nesquena commented 13 years ago

So you want to be forced to do PADRINO_ENV=test rake spec for every single test run? I don't normally see this in Rails or plain Sinatra being required to specify the test env in a test rake task. But I will leave it up to you and @achiu to decide what to do here.

DAddYE commented 13 years ago

generally I use padrino rake spec -e test

achiurizo commented 13 years ago

@yuya-takeyama are you using the default Padrino generated spec_helper.rb? that should load your PADRINO_ENV for you

yuya-takeyama commented 13 years ago

@achiu Yes. The default one.

PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")

RSpec.configure do |conf|
  conf.include Rack::Test::Methods
end

def app
  ##
  # You can handle all padrino applications using instead:
  #   Padrino.application
  TestProject.tap { |app|  }
end
dcu commented 12 years ago

this is doesn't work on heroku

wakatara commented 12 years ago

Yep... I have to agree (sorry DAddyE), that should be changed. It causes issues and violates 'least surprise'

Passing the padrino env is neither intuitive or expected behaviour.

I came by this post because heroku exploded when I tried starting up a rake task wchich works fine in dev on my machine.

marcosdsanchez commented 12 years ago

I also had problems with this before, see https://github.com/padrino/padrino-framework/commit/f6708d845fbfbeadbff27f6e49b0e09d8717a736

smertrios commented 12 years ago

Hi, what's the proper fix on heroku?

On heroku, I set "PADRINO_ENV=production" but running "heroku run rake dm:migrate" still fails with the same "no such file to load -- rspec/core/rake_task"

For now, replacing Gemfile: gem "rspec" does the trick but I have rspec installed in production.

maca commented 12 years ago

Quick fix for deploying to heroku:

spec/spec.rake

if ENV['PADRINO_ENV'] == 'test'
  require 'rspec/core/rake_task'

  spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }

  spec_tasks.each do |folder|
    RSpec::Core::RakeTask.new("spec:#{folder}") do |t|
      t.pattern = "./spec/#{folder}/**/*_spec.rb"
      t.rspec_opts = %w(-fs --color)
    end
  end

  desc "Run complete application spec suite"
  task 'spec' => spec_tasks.map { |f| "spec:#{f}" }
end

Could the rake tasks in spec/ and test/ be ignored unless env is test?