Peter Tretiakov
Peter Tretiakov

Reputation: 3410

undefined method `should' for Date

I'm trying to test behavior between 2 models

In BudgetRule model I have after_create method, which creates Transaction (another model).

I want to test action_start column in created transaction. In my tests it should be equal Date.today. So my BudgetRule test is the following:

require 'rspec'

describe BudgetRule do

  user = FactoryGirl.create(:user)
  let(:budget_rule) { FactoryGirl.build(:budget_rule, user: user) }

  subject { budget_rule }

  it 'should add proper action start' do
    budget_rule.save!
    budget_transaction = Transaction.find_by(user: user, budget_rule: budget_rule)
    budget_transaction.action_start.should == Date.today
  end
end

But I receive

NoMethodError: undefined method `should' for Wed, 26 Feb 2014:Date

Thanks for any help!

UPDATE:

When I make:

budget_transaction.action_start should == Date.today #without dot before "should"

I receive

expected: Wed, 26 Feb 2014
     got: #<BudgetRule id: 7, ...and so on... "> (using ==)

Upvotes: 0

Views: 145

Answers (1)

Peter Tretiakov
Peter Tretiakov

Reputation: 3410

So, after several fails, working tests are:

require 'rspec'

describe BudgetRule do

  user = FactoryGirl.create(:user)
  budget_rule = FactoryGirl.create(:budget_rule, user: user)
  budget_transaction = Transaction.find_by(user: user, budget_rule: budget_rule)

  subject { budget_transaction }

  it 'should add proper action start' do
    expect(budget_transaction.action_start).to eq Date.today
  end

end

Hope it will help somebody some day :)

Upvotes: 1

Related Questions