我跟着 Trailblazer 这本书向我学习了一些 Trailblazer。昨天,我所有的测试都是绿色的。今天,我尝试添加rails-timeago
助手,我遇到了一些麻烦,但我最终设法解决了。在我让 gem 工作之后,我重新运行了我现有的测试,令我惊讶的是,所有测试都是红色的,并且应该归咎于现有的操作。
我打开了一个 rails 控制台来测试我的操作,所以我做了一个Create.
,它确实在那里失败了。我的想法已经不多了,谷歌也没有特别帮助我。
这是错误代码(在 Rails 控制台上):
irb(main):004:0> Thing::Create.(thing: {name: 'Rails', description: 'Kiackass web app'}) #: Thing::Create:Class 的未定义方法 `class_builder' 你的意思?类属性 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/trailblazer-1.1.1/lib/trailblazer/operation/builder.rb:20:in `build_operation_class' 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/trailblazer-1.1.1/lib/trailblazer/operation/builder.rb:24:in `build_operation' 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/trailblazer-1.1.1/lib/trailblazer/operation.rb:34:in `call' 来自 (irb):4 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start' 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start' 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console' 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!' 来自 C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `' 从 bin/rails:4:in `require' 从 bin/rails:4:in `'
这是我当前的 gemfile:
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem "sass-rails"
gem "uglifier"
gem "coffee-rails"
gem "jquery-rails"
gem "foundation-rails"
gem "haml-rails"
gem "simple_form"
gem "therubyracer", :platform=>:ruby
gem "thin"
gem "sqlite3"
group :development do
gem "binding_of_caller", :platforms=>[:mri_21]
gem "rails_layout"
end
gem "responders"
group :development, :test do
gem "minitest-rails-capybara"
gem "minitest-line"
gem "minitest-reporters"
gem "win32console"
end
group :test do
gem 'memory_test_fix'
end
group :production do
gem "rails_12factor"
end
gem "reform"
# gem "reform", github: "apotonick/reform", branch: "reform-2"
#gem "reform", path: "../reform"
# gem "representable", path: "../representable"
gem "representable"
# gem "reform", "2.0.4"
# gem "disposable", github: "apotonick/disposable"
gem "virtus"
# gem "disposable", path: "../disposable"
gem "tyrant"
# gem "tyrant", path: "../tyrant"
gem "trailblazer"
gem "trailblazer-loader"
gem "trailblazer-rails"
# gem "trailblazer", path: "../trailblazer"
# gem "trailblazer-loader", path: "../trailblazer-loader"
# gem "trailblazer-rails", path: "../trailblazer-rails"
# gem "disposable", path: "../disposable"
# gem "trailblazer-rails", ">= 0.1.3"
# gem "cells", git: "https://github.com/apotonick/cells"
# gem "cells", path: "../cells"
gem "cells"
gem "cells-haml"
gem "haml", github: "haml/haml", ref: "7c7c169"
gem "kaminari-cells"
gem "paperdragon"
gem "file_validators"
# gem "roar", path: "../roar" #"1.0.0"
gem "roar"
gem "pundit"
gem "rails-timeago"
gem "email_validator"
gem "foundation-icons-sass-rails"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
这是运营商的代码:
class Thing < ActiveRecord::Base
class Create < Trailblazer::Operation
include Model
model Thing, :create
contract do
property :name
property :description
validates :name, presence: true
validates :description, length: {in: 4..160}, allow_blank: true
end
def process(params)
validate(params[:thing]) do |f|
f.save
end
end
end
class Update < Create
action :update
contract do
property :name, writeable: false
end
end
end
这是我的一些测试的代码:
require 'test_helper'
class ThingCrudTest < Minitest::Spec
describe "Create" do
it "persists valid" do
thing = Thing::Create.(thing: {name: 'Rails', description: 'Kickass web dev'}).model
thing.persisted?.must_equal true
thing.name.must_equal 'Rails'
thing.description.must_equal "Kickass web dev"
end
it "invalid name" do
res, op = Thing::Create.run(thing: {name: ""})
res.must_equal false
op.model.persisted?.must_equal false
op.contract.errors.to_s.must_equal "{:name=>[\"can't be blank\"]}"
end
it "invalid description" do
res, op = Thing::Create.run(thing: {name: "Rails", description: "hi"})
res.must_equal false
op.contract.errors.to_s.must_equal"{:description=>[\"is too short (minimum is 4 characters)\"]}"
end
end
describe "Update" do
let (:thing) do
Thing::Create.(thing: {name: "Rails", description: "Kickass web dev"}).model
end
it "persists valid, ignores name" do
new_thing = Thing::Update.(id: thing.id, thing: {name: "Rails", description: "Simply better"}).model
new_thing.name.must_equal "Rails"
new_thing.description.must_equal "Simply better"
end
end
end
这是测试的输出:
从运行选项开始 --seed 46307 错误[“test_0002_invalid name”,#,0.00465575500857085]? test_0002_invalid name#Create (0.01s) NoMethodError:NoMethodError:Thing::Create:Class 的未定义方法“class_builder” 你的意思?类属性 test/concepts/thing/crud_test.rb:14:in `block (2 levels) in ' 错误[“test_0001_persists 有效”,#,0.0119611140107736] test_0001_persists 有效#创建 (0.01s) NoMethodError:NoMethodError:Thing::Create:Class 的未定义方法“class_builder” 你的意思?类属性 test/concepts/thing/crud_test.rb:6:in `block (2 levels) in ' 错误["test_0003_invalid description", #, 0.019230154925026] test_0003_invalid description#Create (0.02s) NoMethodError:NoMethodError:Thing::Create:Class 的未定义方法“class_builder” 你的意思?类属性 test/concepts/thing/crud_test.rb:22:in `block (2 levels) in ' 错误[“test_0001_persists 有效,忽略名称”,#,0.031214163987897336] test_0001_persists 有效,忽略 name#Update (0.03s) NoMethodError:NoMethodError:Thing::Create:Class 的未定义方法“class_builder” 你的意思?类属性 test/concepts/thing/crud_test.rb:31:in `block (2 levels) in ' test/concepts/thing/crud_test.rb:35:in `block (2 levels) in ' 错误 [“test_0001_allows 匿名”,ThingIntegrationTest,0.06196290999650955] test_0001_allows anonymous#ThingIntegrationTest (0.06s) NoMethodError:NoMethodError:Thing::Create:Class 的未定义方法“class_builder” 你的意思?类属性 app/controllers/things_controller.rb:3:in `new' test/integration/thing_test.rb:5:in `block in ' 5/5: [====================================] 100% 时间: 00:00:00 , 时间: 00:00:00 0.07067s 完成 5 次测试,0 次断言,0 次失败,5 次错误,0 次跳过
这是一个gem list
供参考的概要。
*** 当地宝石 *** 可操作的 (5.0.0.1) actionmailer (5.0.0.1, 4.2.7.1) 动作包(5.0.0.1、4.2.7.1) 动作视图(5.0.0.1、4.2.7.1) 活动作业(5.0.0.1、4.2.7.1) 活动模型(5.0.0.1、4.2.7.1) 活动记录(5.0.0.1、4.2.7.1) 主动支持(5.0.0.1、4.2.7.1、4.2.4) act_as_commentable (4.0.2) 可寻址 (2.5.0) 安西 (1.5.0) 阿雷尔(7.1.4、7.1.3、6.0.3) ast (2.3.0) autoprefixer-rails (6.5.3, 6.5.0.2, 6.4.0.3) aws-sdk-core (2.6.6) 公理类型 (0.1.1) 通天塔源 (5.8.35) babel-transpiler (0.7.0) bcrypt (3.1.11 ruby x64-mingw32, 3.1.7 x64-mingw32) 更好的错误(2.1.1) 大十进制(默认值:1.2.8) binding_of_caller (0.7.2) 引导形式(3.0.0) 引导字形图标 (0.0.1) 引导 sass (3.3.7) 引导-will_paginate (0.0.10) bootstrap_form (2.5.2) 建设者(3.2.2) 捆绑器(1.13.6、1.13.2) byebug (9.0.6, 8.2.1) 水豚 (2.11.0, 2.10.2, 2.10.1) 细胞(4.1.5、4.1.4、4.1.3) 细胞-haml (0.0.10) 细胞导轨(0.0.6) 城邦 (0.0.13) 码雷 (1.1.1) 强制 (1.0.0) 咖啡轨 (4.2.1) 咖啡脚本(2.4.1) 咖啡脚本源(1.11.1、1.10.0) 并发红宝石(1.0.2、1.0.0) 守护进程 (1.2.4) database_cleaner (1.5.3, 1.5.2) debug_inspector (0.0.2) 声明性 (0.0.8) descendants_tracker (0.0.4) did_you_mean (1.0.0) 一次性(0.3.2) 温顺(1.1.5) dotenv (2.1.1) 蜻蜓 (1.0.12) 干式可配置(0.3.0) 干燥容器 (0.5.0) 干核 (0.2.1) 干式均衡器 (0.2.0) 干逻辑(0.4.0) 干式 (0.9.2) 干验证(0.10.3) email_validator (1.6.0) 均衡器 (0.0.11) 厄鲁比斯 (2.7.0) 事件机(1.2.1 x64-mingw32) execjs (2.7.0, 2.6.0) 伪造者(1.4.2) ffi (1.9.14 x64-mingw32) 文件验证器 (2.1.0) 格式化程序(0.2.5) 基础图标-sass-rails (3.0.0) 基础导轨(6.2.4.0) globalid (0.3.7) glyphicons-rails (0.1.2) 守卫(2.13.0) 守卫兼容(1.2.1) 守卫-minitest (2.4.4) 哈姆 (4.0.7) 哈姆林特 (0.999.999) haml-rails (0.9.0) haml_lint (0.18.4) 花见 (0.9.1) hanami-assets (0.4.0) hanami 控制器 (0.8.0) 赏花助手 (0.5.0) hanami-mailer (0.4.0) 花见模型(0.7.0) 花见路由器 (0.8.1) hanami-utils (0.9.1) hanami 验证 (0.7.1) 花见视图 (0.8.0) 锄头 (3.15.2) 锄头捆绑器 (1.3.0) hpricot (0.8.6) html2haml (1.0.1) http_router (0.11.2) httparty (0.13.7) i18n (0.7.0) 冰九 (0.11.2) 变形 (0.0.2) io 控制台(默认值:0.4.5) jbuilder (2.6.1, 2.6.0, 2.4.1) jmespath (1.3.1, 1.2.4) jquery-rails (4.2.1, 4.1.1) json(默认值:1.8.3) json_pure (1.8.3) 雷神 (0.17.0) kaminari 细胞 (0.0.4) 听(3.0.8) 丝瓜 (2.0.3) 伐木工人 (1.0.10) 邮件(2.6.4、2.6.3) memory_test_fix (1.4.0, 1.3.0) 方法源(0.8.2) 哑剧类型 (3.1, 2.99) 哑剧类型数据 (3.2016.0521) mini_portile (0.6.2) mini_portile2 (2.1.0, 2.0.0) 迷你测试(5.10.1、5.9.1、5.8.4、5.8.3) minitest-水豚 (0.8.2) minitest-line (0.6.3) minitest-元数据 (0.6.0) minitest-rails (3.0.0, 2.2.1) minitest-rails-capybara (3.0.0, 2.1.2) minitest-reporters (1.1.13, 1.1.12, 1.1.9) minitest-spec-rails (5.4.0) multi_json (1.12.1, 1.11.2) multi_xml (0.5.5) mysql2 (0.4.4 x64-mingw32, 0.4.2 x64-mingw32) nenv (0.3.0) 嵌套形式(0.3.2) 网络远程登录 (0.1.1) nio4r (1.2.1) nokogiri (1.6.8.1 x64-mingw32) 通知 (0.1.1) orm_adapter (0.5.0) 纸龙 (0.0.11) 解析器(2.3.3.1) pg (0.19.0 x64-mingw32, 0.17.1 x64-mingw32) power_assert (0.2.6) 电源组 (0.1.1) 撬 (0.10.4) 心理(默认:2.0.17) public_suffix (2.0.4) 彪马(3.6.2、3.6.0、3.4.0) 权威人士 (1.1.0) 安静的资产(1.1.0) 机架(2.0.1、1.6.5、1.6.4) 机架测试(0.6.3) 导轨(5.0.0.1、4.2.7.1) rails-assets-datatables.net (1.10.12, 1.10.10) rails-assets-jquery (3.1.1, 2.2.0) rails-controller-testing (0.1.1) rails-deprecated_sanitizer (1.0.3) rails-dom-testing (2.0.1, 1.0.7) rails-html-sanitizer (1.0.3) rails-timeago (2.15.0) rails_12factor (0.0.3, 0.0.2) rails_layout (1.0.34) rails_serve_static_assets (0.0.5, 0.0.4) rails_stdout_logging (0.0.5, 0.0.4) 铁轨(5.0.0.1、4.2.7.1) 彩虹 (2.1.0) 耙子 (12.0.0, 11.3.0, 10.5.0, 10.4.2) rake 编译器 (0.9.9) rake-compiler-dock (0.5.3) rb-fsevent (0.9.7) rb-inotify (0.9.7) rdoc(4.2.2,默认:4.2.1) 改革(2.2.3、2.2.2) 改革轨道(0.1.7) 可表示的 (3.0.2, 3.0.1) 响应者 (2.3.0) 咆哮 (0.12.7) 只读存储器 (2.0.2) ROM映射器(0.4.0) ROM 存储库 (0.3.1) 只读存储器 (0.9.0) ROM 支持 (2.0.0) rubocop (0.46.0) 红宝石进度条(1.8.1) ruby_parser (3.1.3) rubyzip (1.2.0) 萨斯 (3.4.22, 3.4.21) sass-rails (5.0.6) sdoc (0.4.2, 0.4.1) 续集 (4.40.0) sexp_processor (4.7.0) 谢兰尼 (0.0.1) 霰弹枪 (0.9.2) simple_form (3.3.1) simplecov (0.12.0, 0.11.1) simplecov-html (0.10.0) 斜坡 (3.6.0) 弹簧(1.7.2、1.6.2) spring-watcher-listen (2.0.0) 链轮 (3.7.0, 3.5.2) 链轮-es6 (0.9.2) 链轮导轨 (3.2.0) sqlite3 (1.3.12 x64-mingw32, 1.3.11 x64-mingw32) sqlite3-ruby (1.3.3) 系统退出 (1.2.0) 测试单元(3.1.5) 薄(1.7.0) 雷神 (0.19.4, 0.19.1) 线程安全(0.3.5) 倾斜 (2.0.5, 2.0.2) timeago-rails (0.1.5) 开拓者 (1.1.2, 1.1.1) 开拓者装载机 (0.1.0) 开拓者轨道 (0.4.0) transproc (0.4.1) 涡轮链接 (5.0.1) turbolinks 源 (5.0.0) 暴君(0.0.3) tzinfo (1.2.2) tzinfo 数据(1.2016.10、1.2016.9、1.2016.8、1.2016.7) 超级 (0.1.0, 0.0.15) 丑化剂(3.0.4、3.0.3、3.0.2、3.0.0、2.7.2) unicode-display_width (1.1.1) url_mount (0.2.1) 美德(1.0.5) 典狱长 (1.2.6) 网络控制台(3.4.0、3.3.1、3.1.1) 网络套接字驱动程序(0.6.4) websocket 扩展 (0.1.2) will_paginate (3.0.7) win32控制台 (1.3.2) 威斯珀 (1.6.1) xpath (2.0.0)
我确信从昨天开始我就没有接触过操作员的代码或任何可能破坏它的东西;我目前正在研究一个细胞。我已经跑了bundle install
好bundle update
几次了。同样,由于昨天所有这一切都按预期工作,我愿意责怪一些宝石恶作剧,但我仍然会得到任何帮助,我将不胜感激。