class Post
has_many :comments
after_update :update_comments
def update_comments(user)
comments.where(user: user).each do |comment|
# binding.pry
comment.do_something
end
end
end
class Comment
belongs_to :post
def do_something
'Ok, I will'
# binding
我正在尝试对RSpec使用Pry。目标是能够在方法中删除绑定并对其进行调试。
这是我所拥有的。
lib/play.rb
class Play
def self.hello
print 'Hello world!'
require 'pry'; binding.pry
end
end
spec/play_spec.rb
require_relative '../lib/play'
describe Play do
it 'Play#hello should print message' do
e
我有一段我正在尝试测试的代码:
def error_from_exception(ex)
if ex.is_a?(ActiveRecord::RecordInvalid)
...
要进入if块,我需要传入正确的ex参数。
如何创建ActiveRecord::RecordIn有效值?
用rspec,我试着做这样的事情:
context 'exception is ActiveRecord::RecordInvalid' do
it 'returns the validation error' do
begin
raise ActiveR
有一个Company类,has_many QuarterValue,我有一个RSpec测试。
let(:company) { Company.create }
describe 'company has many quarter values' do
before do
10.times { create(:quarter_value, company: company) }
end
it 'has 10 quarter values' do
expect(company.quarter_values.co
我正在尝试对方法使用binding.pry并对其进行调试。 这是我想要做的一个简单的例子。 hello.rb class Hello
def self.hello
'Hello world!'
binding.pry
end
end spec/hello_spec.rb describe Hello do
it 'Hello#hello should print message' do
expect {Hello.hello}.to eq('Hello world!')
end
end 我想调试self.hello方法,如何
我要把RSpec/Capybara测试的测试执行转移到AWS设备场。在发送个人句号(".")时,我遇到了问题。一片田地。下面是我的binding.pry调试会话:
[5] pry(#<RSpec::ExampleGroups::Drivers>)> find('input[id^="filter"]').set('.')
Selenium::WebDriver::Error::WebDriverError: You are trying to work with something that isn't
请帮助显示current_user。
我使用rails4 + devise + rspec +水豚。我尝试登录用户。
测试:
it 'check display username on top panel' do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
sign_in user
visit root_path
binding.pry
end
工厂:
FactoryGirl.define do
我正在使用Rspec,Capybara和设计。我需要能够登记。
我的测试:
describe "POST #create" do
context "with valid params" do
it "creates a new Poll" do
@user = FactoryGirl.create(:user)
visit new_user_session_path
fill_in "user_email", :with => @user.email
fill_
我是Rspec的新手。我正在编写一个测试用例,以涵盖模型中的一些操作。以下是我的rspec代码
test_cover_image_spec.rb
require 'spec_helper'
describe Issue do
before :each do
@issue = Issue.joins(:multimedia).uniq.first
binding.pry
end
describe '#release_cover_image' do
context 'While making an issu
我在这本书“用RSpec进行日常Rails测试”( Everyday Rails Testing with RSpec)中继续学习,它使用了assigns
it "assigns the requested Category to @category" do
category = FactoryGirl.create(:category)
binding.pry
get :edit, id: category
expect(assigns(:category)).to eq category
end
然而,我的测试失败了,所以我使用pry来挖掘(如上面所示)
[
我在Rails 6中使用Rspec 3.8.0。
我有一个模型A,它是belongs_to B.,我试图用A作为subject编写一个单元测试。
expect(subject.b).to receive(:to_s)
subject.my_fn
然而,这个规范总是失败的,它说B的实例没有接收到消息,尽管我已经将binding.pry放在实际的代码中运行,并验证了a.b.to_s是否被调用:
class A
def my_fn
binding.pry
b.to_s
end
end
我甚至试过:
expect(a).to receive(:b).and_return(b)
我的控制器从ApplicationController继承动作。我的目标是测试任何继承自ApplicationController的控制器的行为。为了实现这个目标,我在自己的规范中创建了RandomController。
这是到目前为止我的规格
require 'rails_helper'
RSpec.configure do |c|
c.infer_base_class_for_anonymous_controllers = false
end
class RandomController < ApplicationController; end
clas
我是Rspec的新手。我正在编写一个测试用例,以涵盖模型中的一些操作。这是我的rspec代码
test_cover_image_spec.rb
require 'spec_helper'
describe Issue do
before :each do
@issue = Issue.joins(:multimedia).uniq.first
binding.pry
end
describe '#release_cover_image' do
context 'While making an issue open
撬动的宝石在测试组中: group :test do
gem 'pry', '~> 0.12.2'
end 它起作用了。 我把它移到了另一组。 group :development, :test do
gem 'pry', '~> 0.12.2'
end 如果我执行rspec,binding.pry就会工作。它会暂停执行,但是如果我只是运行docker-compose up来启动本地开发环境,并在某个地方添加binding.pry,它就无法工作。 我遵循链接here并重新构建了容器。启动了容器,但是,bind
我最近开始用rspec进行测试,所以我可能会大错特错,如果有更好的方法,请纠正我。
我创建了两个相关的模型
let(:user) {FactoryGirl.create :user}
let!(:participation) {FactoryGirl.create :participation, user: user}
在其中一个测试更改其中一个相关对象之前
context "when" do
before {participation.prize = 100}
it "" do
binding.pry
end
end
但在里面
parti
我尝试在测试环境中调试我的user_mailer.rb。但是我不知道为什么调试器不停在它应该停的地方。
因此,我大致拥有的代码是:user_mailer_spec.rb
describe UserMailer do
describe '#send_notification_letters' do
# bunch of code omitted here ...
it 'should record itself to the database'
expect { UserMailer.send_notification_letter
我的一次测试有问题
Rspec
it 'should call send_email_notification on NotificationMailer' do
expect(NotificationMailer).to receive(:user_notification).with(an_instance_of(User))
FactoryGirl.create(:user, shop: Shop.new)
end
方法:
def send_email_notification
if user? && self.shop.
Rails 5现在出来了,我正在升级我的基本登录/CRUD应用程序,以使用新的框架,这涉及到升级到4.2。事情非常简单,除了一个失败的rspec测试。我试着用pry来完成代码,但是发现这个问题超出了我的能力范围。如有任何指示,将不胜感激。
这是一个错误:
Failures:
1) User email rejects email addresses with improper format
Failure/Error: expect(user).not_to be_valid
ArgumentError:
wrong number of arguments (given 0,
我有以下模块/类结构:
module A
module B
class Foo; end
class Bar
MY_CONST = 42
end
end
end
我在我的RSpec测试中放了一个binding.pry。如果我访问
A::B::Bar::MY_CONST
我得到错误: NameError: unitialized A::B::Bar
如果然后执行A::B::Foo,则会得到对象A::B::Foo
然后,如果我第二次做A::B::Bar::MY_CONST,我得到42。
如果我将类栏嵌入到类Foo中,并使用A::B::Foo::Bar::