簡體   English   中英

在Cloud 9 IDE中撬入RSpec

[英]pry on rspec in cloud 9 ide

我是RoR的新手。 我這里有兩個問題。 問題1我的rspec是

require 'spec_helper'
describe RefUserCategory do
    describe "validations" do
        it { should validate_presence_of(:user_category_description) }
    end
end

我的Ref_User_Category模型是

class RefUserCategory < ActiveRecord::Base
    validate :user_category_description , presence: true
    has_many :Users
end

我在Expected errors to include /can't be blank/ when user_category_description is set to nil, got no errors

所以我決定使用Pry來檢查發生了什么

問題2我在我的應用程序文件夾中

pry -r ./config/environment

[2] pry(main)> Ref_User_Category.new
LoadError: Unable to autoload constant Ref_User_Category, expected /var/lib/stickshift/52d29d0e5004461024000031/app-root/data/736003/east/app/models/ref_user_category.rb to define it
from /var/lib/stickshift/52d29d0e5004461024000031/app-root/data/lib/ruby/gems/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:464:in `load_missing_constant'

我也有用戶模型

pry(main)> User.new

給出錯誤

ActiveRecord::StatementInvalid: Could not find table 'users'

/app-root/data/lib/ruby/gems/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:512:in `table_structure'

關於問題1 ,您有一個錯字:將validate更改為validates

關於問題2

通常,您可以從項目的根目錄啟動控制台,如下所示:

$ rails c

您在執行Ref_User_Category.new時正在執行RefUserCategory.new

關於User.new ,您似乎尚未運行數據庫遷移:

$ rake db:migrate
$ rake db:test:prepare

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM