如何访问 pic
在我的rspec测试中?我不断得到以下错误:
F
Failures:
1) TrelloToAc::Card#pic return pic url from trello card
Failure/Error: expect(result).to be_a String
expected :pic to be a kind of String
# ./spec/services/trello_to_ac/card_spec.rb:17:in `block (3 levels) in <top (required)>'
Finished in 1.97 seconds (files took 13.5 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/services/trello_to_ac/card_spec.rb:14 # TrelloToAc::Card#pic return pic url from trello card
这似乎需要时间 pic
字面上,就像一根绳子。这是我的密码:
测试:
require 'rails_helper'
RSpec.describe TrelloToAc::Card do
describe '#pic' do
it 'return pic url from trello card' do
result = @pic
puts result
expect(result).to be_a String
end
end
end
正在测试的代码:
class TrelloToAc::Card
#
#
def pic
@pic ||= card.attachments.last.url if card.attachments.any?
end
#
#
end
1条答案
按热度按时间8yoxcaq71#
这就是我最终解决这个问题的原因。我认为这与我的一些评论者所说的更为接近。这还提供了有关
pic
测试:实际代码:
这样,我测试的是类的一个示例,而不是示例变量。我对其他方法也有类似的测试。