小编jos*_*221的帖子

切换到工厂机器人后错误工厂未注册

我在spec_helper.rb中有工厂机器人

config.include FactoryBot::Syntax::Methods
Run Code Online (Sandbox Code Playgroud)

所以我将工厂从 FactoryGirl 更新为 FactoryBot 如下

规格/工厂/产品.rb

FactoryBot.define do
  factory :products do
    id Faker::Number.between(100, 900)
    ...more fields...
  end
end
Run Code Online (Sandbox Code Playgroud)

并尝试在请求规范中使用它,如下所示

规格/请求/products_request_spec.rb

require 'rails_helper'

RSpec.describe 'Products Request', type: :request do
  let(:products) { FactoryBot.create(:products) }
  let(:base_path) { '/products' }
 .....something here...
end
Run Code Online (Sandbox Code Playgroud)

当我尝试运行测试时,我得到了factory not registerd: products。我做错了什么?

ruby rspec ruby-on-rails-4 factory-bot

4
推荐指数
1
解决办法
1569
查看次数

如何关闭环复杂度过高的情况

我在模型中有一个 where 方法抛出 lint 错误。model中的全部代码目前只是测试代码,稍后会进行重构。所以我想暂时关闭这个 lint 错误。

更新:这是我收到 lint 错误的方法

def self.where(start_date, end_date, customer_id, type, location, is_registered)
  filtered_data = if start_date && end_date
                     customers.select do |e|
                       e[:startDateTime].to_datetime >= start_date.to_datetime &&
                         e[:endDateTime].to_datetime <= end_date.to_datetime
                     end
                   elsif start_date
                     customers.select {|e| e[:startDateTime].to_datetime >= start_date.to_datetime }
                   elsif end_date
                     customers.select {|e| e[:endDateTime].to_datetime <= end_date.to_datetime }
                   else
                     customers
                   end

  if !is_registered.nil? # is_registered is true or false
    filtered_data = customers.select { |e| e[:isRegistered].to_s == is_registered }
  end
  # Check if hash presents and check if …
Run Code Online (Sandbox Code Playgroud)

ruby rubocop

3
推荐指数
1
解决办法
6262
查看次数

我如何将两个 props 从 jsx 传递到 scss

我有以下两个道具,我需要在线性渐变中访问它们MyComponent.scss

startColor: PropTypes.string
endColor: PropTypes.string
Run Code Online (Sandbox Code Playgroud)

我的组件如下所示

MyComponent.jsx

<myComponent 
  {...customProps}
  style={{color: customProps.color }}
  className={classess}
  ...other props here..
  />
Run Code Online (Sandbox Code Playgroud)

目前它只接受一种颜色。

线性梯度属性MyComponent.scss如下所示

linear-gradient(to left, currentcolor, currentcolor);
Run Code Online (Sandbox Code Playgroud)

它将更新为使用 startColor 和 endColor。

我怎样才能做到这一点?

jsx reactjs

3
推荐指数
1
解决办法
2万
查看次数

运行bundle install时出错:bundle被锁定到解析器

我刚刚克隆了一个新的仓库并尝试运行bundle install但是遇到了错误

Fetching gem metadata from https://abcderepos.net/api/gems/rubygems/...........
Your bundle is locked to parser (2.5.0.4), but that version could not be found in any of the sources listed in your Gemfile. If
you haven't changed sources, that means the author of parser (2.5.0.4) has removed it. You'll need to update your bundle to a
different version of parser (2.5.0.4) that hasn't been removed in order to install.
Run Code Online (Sandbox Code Playgroud)

知道我为什么会收到这个错误吗?

bundle bundler

3
推荐指数
2
解决办法
1400
查看次数

标签 统计

ruby ×2

bundle ×1

bundler ×1

factory-bot ×1

jsx ×1

reactjs ×1

rspec ×1

rubocop ×1

ruby-on-rails-4 ×1