Я могу запустить свои тесты, просто запустив части своего кода через RubyMine (щелкните правой кнопкой мыши файл _spec.rb и запустите).Но, запустив "rake spec", я получаю ошибку.Таблица удаляется и не перестраивается перед каждым тестом.Я знаю, что это имеет смысл, но нет, если он не будет восстановлен снова.
Такие вещи, как db: test: load, db: test: prepare, db: test: clone_sturcture также не работают. Когда я просто запускаю "rake spec"Я получаю следующие ошибки:
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