私はまだRubyのスキルを向上させています。より良いRuby構文を使ってこのテストをクリーンアップする方法
私はRSpecのテストのためにこのコードを乾かすことができるかどうかを把握しようとしている:
require 'rails_helper'
RSpec.describe Role, type: :model do
describe "has several roles types " do
before :each do
@roles = Role.all
end
context "The role types that are valid" do
it "includes 'proofreader', 'admin', 'super_admin' " do
expect(@roles.any?{|r| r.name == 'proofreader'}).to be_truthy
expect(@roles.any?{|r| r.name == 'admin'}).to be_truthy
expect(@roles.any?{|r| r.name == 'super_admin'}).to be_truthy
end
end
context "The role types that are not valid " do
it "includes 'developer' " do
expect(@roles.any?{|r| r.name == 'developer'}).to be_falsy
end
end
end
end
具体的に私がダウンして1に、コードのこれらの3本のラインを減らしたいが、それはどのように私の目を逃れています1行に3つの文字列値のActiveRecord関係をチェックします。 アイデア
あなたは 'true'を代わりにする'使用する必要がありますbe_truthy'。違いを見てください。 –