小编vic*_*ich的帖子

RSpec 3.5 将参数传递给 shared_context

我有这个代码,我想在几个规范中重用:

RSpec.shared_context "a UserWorker" do |user|

  let(:mock_context_user) {{
    id: 1,
    brand: user.brand,
    backend_token: user.backend_token
  }}

  before(:each) do
    allow(SomeClass).to receive(:some_method)
      .with(user.id).and_return(mock_context_user)
  end

  before(:each, context: true) do
    Sidekiq::Testing.inline!
  end

  after(:each, context: true) do
    Sidekiq::Testing.fake!
  end

end
Run Code Online (Sandbox Code Playgroud)

在使用共享代码的规范文件中:

let(:user) { build :user } # FactoryGirl

...

describe '#perform' do
  # some lets here

  include_context 'a UserWorker', user

  context 'when something exists' do
    it 'does some stuff' do
      # test some stuff here
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

但这给了我这个错误:

/.rvm/gems/ruby-2.3.0@fb-cont/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:724:in `method_missing': `user` is not available on …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails rspec-rails rspec3 ruby-on-rails-5

4
推荐指数
2
解决办法
2359
查看次数

活动记录栏上的条件3

我正在尝试添加一个条件,其中只从模型中获取满足条件的记录.例如,我试图只从Transaction模型中获取:price大于或不等于0的记录(我已尝试>和!=但在下面的示例中都没有工作).

price = Transaction.where(:company_id => company).where(:price != 0.00)
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

price = Transaction.where(:company_id => company).where(:price != 0.00).collect{|item| if item.price.to_f > 0.00 {item.price.to_f} end}
Run Code Online (Sandbox Code Playgroud)

......以及上述两种不起作用的其他变体.

上面的第一个示例不会产生错误,但根本不起作用.条件被忽略了.第二个示例产生语法错误.

我也很确定有一种方法可以在SQL中使用条件,但不知道如何去做.

有什么建议?

ruby activerecord ruby-on-rails ruby-on-rails-3 rails-activerecord

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

使用RVM安装Ruby 1.9.3时运行'autoconf'时出错

我使用的是Mac OS X 10.7.4,目前正在使用Ruby 1.9.2.我正在尝试使用RVM安装Ruby 1.9.3但在执行时遇到以下错误rvm install 1.9.3:

Running autoconf
Error running 'autoconf', please read .../.rvm/log/ruby-    1.9.3/autoconf.log
Skipping configure step, 'configure' does not exist, did autoconf not run successfully?
ruby-1.9.3 - #compiling 
Error running 'make ', please read .../.rvm/log/ruby-1.9.3/make.log
There has been an error while running make. Halting the installation.
Run Code Online (Sandbox Code Playgroud)

我什么也没有发现在这两个有用的autoconf.logmake.log.

我看了类似的问题,但无法解决这个问题.我也尝试删除ruby-1.9.2-p0 directory问题中的建议.

我真的可以在这里使用一些帮助(以及为什么会发生这种情况的可能解释).

谢谢.

ruby autoconf makefile rvm ruby-1.9.3

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

语法错误,意外':',期待')'使用Rails 3的条带形式

我正在关注Ryan Bates的RailsCast#288"Billing with Stripe",当我修改我的表单以包含信用卡信息时,我收到以下错误:

compile error
/Programs/domainster/app/views/domains/_form.html.erb:23: syntax error, unexpected ':',    expecting ')'
...d_tag :card_number, nil, name: nil );@output_buffer.safe_con...
Run Code Online (Sandbox Code Playgroud)

我检查了RailsCast的语法,代码完全相同.我甚至更新了我的GemFile以确保我有最新的Rails运行.

这是我的表格:

<div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :description %><br />
    <%= f.text_area :description %>
  </div>
  <div class="field">
    <%= label_tag :card_number, "Credit Card Number" %><br />
    <%= text_field_tag :card_number, nil, name: nil %>
  </div>
  <div class="field">
    <%= label_tag :cvv, "Security Code on Card (CVV)" %><br />
    <%= text_field_tag :cvv, nil, name: …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails syntax-error railscasts ruby-on-rails-3

0
推荐指数
1
解决办法
2518
查看次数

如何在Ruby中的when子句中编写带有多个语句的case语句?

我尝试用逗号分隔when子句中的语句,但是它不起作用。

当1; 陈述声明陈述

当2; 陈述声明陈述

我在网上找不到任何示例。

case selection
when 1
  system "clear"
  view_all_entries
  main_menu
when 2
  system "clear"
  create_entry
  main_menu
when 3
  system "clear"
  search_entries
  main_menu
when 5
  puts "Good bye!"
  exit(0)
else
  system "clear"
  puts "Sorry, that is not a valid input"
  main_menu
end
Run Code Online (Sandbox Code Playgroud)

ruby

0
推荐指数
3
解决办法
3564
查看次数