开发者

rspec with change method returning wrong number of arguments 0 for 1

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!


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜