2012-11-11 30 views
2

最近,我開始深入Ruby MVC,以便找到構建我的應用程序的最好,最快,最小的框架。對Rails不滿意,我決定嘗試Padrino。我還第一次嘗試使用TDD外部版完整應用程序,因此能夠爲所有組件編寫測試非常關鍵。不幸的是,我無法在Padrino中製作模型,所以我想知道它是否只是測試版軟件的原因,或者只是我的錯誤。Padrino和RSpec不適用於續集?

我首先創建我的項目,使用Cucumber和RSpec進行測試,然後使用我的ORM的Sequel。

$ padrino g project test -d sequel -t cucumber -c sass -b 

接下來,我創建了一些模型和遷移:

$ padrino g model user 

# ./db/migrate/001_create_users.rb 
Sequel.migration do 
    change do 
    create_table :users do 
     primary_key :id 
     String :name 
     String :password 
    end 
    end 
end 

接下來,當然,來規範。例如起見,只是一些簡單的:

# ./spec/models/user_spec.rb 
require 'spec_helper' 

describe User do 
    it 'can be created' do 
    user = User.create 
    end 
end 

現在,遷移和運行規範:

$ padrino rake sq:migrate:up 
$ rspec spec 

F 

Failures: 

    1) User can be created 
    Failure/Error: user = User.create 
    Sequel::DatabaseError: 
     SQLite3::SQLException: no such table: users 
    # ./spec/models/user_spec.rb:5:in `block (2 levels) in <top (required)>' 

Finished in 0.00169 seconds 
1 example, 1 failure 

Failed examples: 

rspec ./spec/models/user_spec.rb:4 # User can be created 

這是非常混亂。正是在這一點上,我認爲進入Padrino控制檯將幫助我解決這個奇怪的問題。我錯了。

$ padrino c 
> User.create 
    => #<User @values={:id=>1, :name=>nil, :password=>nil}> 
> User.all 
    => [#<User @values={:id=>1, :name=>nil, :password=>nil}>] 

很公平的結果,但後來我嘗試將其與test環境:

$ padrino c -e test 
> User.create 
    Sequel::DatabaseError: SQLite3::SQLException: no such table: users 

我知道,回報率,獲得綜合模式來運行,你必須做一些像rake db:test:prepare,但做padrino rake -T似乎沒有透露任何等價物(用Sequel,DataMapper和ActiveRecord測試;沒有一個似乎有db:test:prepare)。所以,我的問題是:如何獲得在Padrino中運行的集成數據庫測試?

回答

6

this forum post,我發現爲什麼db:test:prepare是這個奇怪的,任意的耙子任務一個需要運行:它與test環境做(與developmentproduction)。在Padrino,這相當於下面的代碼,這是比較模糊一點,但更直觀以及:

$ padrino rake sq:migrate:up -e test 

這告訴Padrino創建表的測試數據庫,這使得規範(或多個)通過。

相關問題