2011-03-09 42 views
0


我可以通過運行我的代碼部分通過RubyMine運行我的測試(右鍵單擊到_spec.rb文件並運行)。但是,通過運行「rake spec」,我得到一個錯誤。表格被移除,並且不會在每次測試中重建。我知道這會讓人感覺到,但如果它不再被重建,就不會有這種感覺。
之類的東西分貝:測試:負載,分貝:測試:準備,分貝:測試:clone_sturcture也不work.When我只是運行 「耙規格」 我得到這個錯誤:Rspec2 Rails3耙規格失敗

C:\RubyStack\ruby\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\RubyStack\ruby\bin\rake spec 
Testing started at 14:11 ... 
(in E:/idun/ComServer_v0.0/source) 
C:/RubyStack/ruby/bin/ruby.exe -S bundle exec rspec ./spec/controllers/customer_controller_spec.rb 
Empty test suite. 

ActiveRecord::StatementInvalid: Mysql2::Error: Table 'comserver_test.customers' doesn't exist: DELETE FROM `customers` 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `rescue in log' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:199:in `log' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:314:in `execute' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:288:in `update_sql' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:331:in `update_sql' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:293:in `delete_sql' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:54:in `delete' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/query_cache.rb:16:in `delete' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/arel-2.0.9/lib/arel/crud.rb:34:in `delete' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/relation.rb:273:in `delete_all' 
C:in `delete_all' 
E:/idun/ComServer_v0.0/source/spec/controllers/customer_controller_spec.rb:20:in `block (2 levels) in <top (required)>' 
C:/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:29:in `instance_eval' 

* _spec。 rb:

require 'spec_helper' 
require 'customer' 
require 'rack/test' 
require 'rspec' 
require 'logger' 

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

def app 
    Rails::Application 
end 

describe "customers" do 

    render_views 

    before(:each) do 
    Customer.delete_all 
    end 

    describe "GET on /customers/:id" do 
    before(:each) do 
     Customer.create(
     :gmsid => 1, 
     :online => true, 
     :pinged_at => DateTime.now 
    ) 
    end 

    it "should return a customer by id" do 
     @response = get("/customers/1") 
     @response.status.should eq(200) 
     attributes = ActiveSupport::JSON.decode(@response.body) 
     attributes['customer']["online"].should be_true 
    end 

    it "should return \"null\" if customer not found" do 
     @response = get('/customers/2') 
     @response.body.to_s.should eq("null") 
    end 
    end 

    describe "should POST on /customers" do 
    it "should create a user" do 
     customer = Customer.new(
     :gmsid => 2, 
     :online => false, 
     :pinged_at => DateTime.now 
    ) 
     puts customer 
     json = ActiveSupport::JSON.encode(customer) 
     @response = post('/customers', json) 
     @response.status.should eq(200) 
     @response = get('/customers/2') 
     attributes = ActiveSupport::JSON.decode(@response.body) 
     attributes['customer']['gmsid'].should eq(2) 
     attributes['customer']['online'].should be_false 
    end 
    end 

    describe "should PUT on /customers/:id" do 
    before(:each) do 
     Customer.create(
     :gmsid => 1, 
     :online => false, 
     :pinged_at => DateTime.now 
    ) 
    end 

    it "should update a user to status true" do 
     @response = put('/customers/1', ActiveSupport::JSON.encode(Customer.new(
      :online => true 
    ))) 
     @response.status.should eq(200) 
     @response = get('/customers/1') 
     attributes = ActiveSupport::JSON.decode(@response.body) 
     attributes['customer']['online'].should be_true 

    end 

    it "when user doesn't exist should return null" do 
     @response = put('/customers/2', ActiveSupport::JSON.encode(Customer.new(
      :online => true 
    ))) 
     @response.status.should eq(200) 
     @response.body.to_s.should eq("null") 
    end 
    end 

    describe "should DELETE on /customers/:id" do 
    it "should delete a existing user" do 
     Customer.create(
      :gmsid => 1, 
      :online => true, 
      :pinged_at => DateTime.now 
    ) 
     @response = get('/customers/1') 
     #test if customer with gmsid 1 is in database 
     @response.status.should eq(200) 
     attributes = ActiveSupport::JSON.decode(@response.body) 
     attributes['customer']['gmsid'].should eq(1) 
     #delete customer with gmsid 1 
     @response = delete ('/customers/1') 
     @response.status.should eq(200) 
     #check if customer with gmsid 1 is not in database anymore 
     @response = get ('/customers/1') 
     @response.status.should eq(200) 
     @response.body.to_s.should eq("null") 
    end 
    end 
end 
+0

我認爲這是db:test:通過做「rake spec」來準備哪些是invoket。如果我手動運行它,它只會破壞我的桌子!? – 2011-03-10 14:02:14

回答

0

好的,我解決了這個問題。

這是討論here的「libmysql.dll問題」。

問題是mysql 5.0版本。它應該高於5.1。所以,我只是將「libmysql.dll」更改爲新版本的mysql版本。有效。 您需要這樣才能從您的開發環境(db:schema:dump)創建適當的轉儲。
該命令在您的項目中創建一個schema.rb。
該模式由「db:test:prepare」使用,在測試之前每次執行「rake spec」時都會調用該模式。這個schema.rb是空的,所以沒有創建表。 聽起來對我來說很合理。

如果我錯了,請糾正我。