rspec 的更改方法返回错误数量的参数 0 为 1

发布于 2024-10-15 08:56:31 字数 1431 浏览 1 评论 0原文

我正在尝试这个测试。

现在

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山有枢 2024-10-22 08:56:31

尝试将其放入 lambda 中:

lambda { @job.publish }.should change(Job.available).from(false).to(true)

另外,我不确定,因为我看不到模型的所有代码,但是您是否打算使用 @job.available 而不是 Job.可用?

编辑:您可能需要使用以下格式:

lambda { @job.publish }.should change(@job, :available).from(false).to(true)

Try putting it in a lambda:

lambda { @job.publish }.should change(Job.available).from(false).to(true)

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 of Job.available?

Edit: You may need to use this format:

lambda { @job.publish }.should change(@job, :available).from(false).to(true)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文