Date.today.to_s(:long)不转换为字符串

问题描述 投票:-1回答:1

我正在做作业,并且根据我们的说明编写了以下方法:

def create_todolist(params)
    due_date = Date.today.to_s(:long)
    TodoList.create(list_name: params[:name],list_due_date: params[:due_date])
end

但是当我运行rspec测试时,出现以下错误:

1) Assignment rq03 rq03.2 assignment code has create_todolist method should create_todolist with provided parameters
     Failure/Error: expect(testList.list_due_date).to eq due_date

       expected: Thu, 07 May 2020
            got: "2020-05-07"

       (compared using ==)

       Diff:
       @@ -1,2 +1,2 @@
       -Thu, 07 May 2020
       +"2020-05-07"

     # ./spec/assignment_spec.rb:177:in `block (4 levels) in <top (required)>'
     # ./spec/assignment_spec.rb:14:in `block (2 levels) in <top (required)>'

这里是rspec测试:

context "rq03.2 assignment code has create_todolist method" do
        it { is_expected.to respond_to(:create_todolist) } 
        it "should create_todolist with provided parameters" do
            expect(TodoList.find_by list_name: "mylist").to be_nil
            due_date=Date.today
            assignment.create_todolist(:name=> 'mylist', :due_date=>due_date)
            testList = TodoList.find_by list_name: 'mylist'
            expect(testList.id).not_to be_nil
            expect(testList.list_name).to eq "mylist"
            expect(testList.list_due_date).to eq due_date
            expect(testList.created_at).not_to be_nil
            expect(testList.updated_at).not_to be_nil
        end  
      end

起初,我只有due_date = Date.today,并且遇到相同的错误,我不确定如何解决。我想知道是否是因为我使用的红宝石/滑轨版本与创建课程时(5年前-_-)使用的版本不同。

任何帮助将不胜感激!

谢谢:)

ruby-on-rails ruby rspec rspec-rails
1个回答
0
投票
您正在尝试比较Date对象:
© www.soinside.com 2019 - 2024. All rights reserved.