rspec 的更改方法返回错误数量的参数 0 为 1
我正在尝试这个测试。
现在
def self.tweet(url)
Twitter.configure do |config|
config.consumer_key = APP_CONFIG['twitter_consumer_key']
config.consumer_secret = APP_CONFIG['twitter_consumer_secret']
config.oauth_token = APP_CONFIG['twitter_access_token']
config.oauth_token_secret = APP_CONFIG['twitter_secret_token']
end
shorted_url = shorten_url(url)
Twitter.update("#{title} - #{shorted_url}")
end
def self.shorten_url(url)
authorize = UrlShortener::Authorize.new APP_CONFIG['bit_ly_id'], APP_CONFIG['bit_ly_api_key']
client = UrlShortener::Client.new authorize
shorten_url = client.shorten(url).urls
end
def publish(url)
update_attributes(:available => true, :locked => false)
tweet(url)
end
,我尝试测试最后一个方法“发布”,但我收到错误数量的参数错误消息。
在测试方面,我有这个:
describe Job, "publish" do
it "should publish a job" do
@job = Factory(:job)
@job.publish.should change(Job.available).from(false).to(true)
end
end
和错误消息:
1) Job Job publish should publish a job
Failure/Error: @job.publish.should change(Job.available).from(false).to(true)
wrong number of arguments (0 for 1)
# ./app/models/job.rb:60:in `publish'
# ./spec/models/job_spec.rb:128:in `block (3 levels) in <top (required)>'
Finished in 1.12 seconds
47 examples, 1 failure, 4 pending
感谢任何帮助!
谢谢!
I'm trying this test.
model
def self.tweet(url)
Twitter.configure do |config|
config.consumer_key = APP_CONFIG['twitter_consumer_key']
config.consumer_secret = APP_CONFIG['twitter_consumer_secret']
config.oauth_token = APP_CONFIG['twitter_access_token']
config.oauth_token_secret = APP_CONFIG['twitter_secret_token']
end
shorted_url = shorten_url(url)
Twitter.update("#{title} - #{shorted_url}")
end
def self.shorten_url(url)
authorize = UrlShortener::Authorize.new APP_CONFIG['bit_ly_id'], APP_CONFIG['bit_ly_api_key']
client = UrlShortener::Client.new authorize
shorten_url = client.shorten(url).urls
end
def publish(url)
update_attributes(:available => true, :locked => false)
tweet(url)
end
for now, I trying to test the last method, "publish" but I'm getting wrong number of arguments error message.
and on the test side, I have this:
describe Job, "publish" do
it "should publish a job" do
@job = Factory(:job)
@job.publish.should change(Job.available).from(false).to(true)
end
end
and the error message:
1) Job Job publish should publish a job
Failure/Error: @job.publish.should change(Job.available).from(false).to(true)
wrong number of arguments (0 for 1)
# ./app/models/job.rb:60:in `publish'
# ./spec/models/job_spec.rb:128:in `block (3 levels) in <top (required)>'
Finished in 1.12 seconds
47 examples, 1 failure, 4 pending
Appreciate any help!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将其放入 lambda 中:
另外,我不确定,因为我看不到模型的所有代码,但是您是否打算使用
@job.available
而不是Job.可用?
编辑:您可能需要使用以下格式:
Try putting it in a lambda:
Also, I'm not sure since I can't see all of your Model's code, but did you mean to use
@job.available
instead ofJob.available
?Edit: You may need to use this format: