【问题标题】:Timecop doesn't work with cucumber capybaraTimecop 不适用于黄瓜水豚
【发布时间】:2019-10-16 18:08:22
【问题描述】:

对不起,我的英语不是我的母语

我有一些时间感测试。这是关于在事件离开前不到 24 小时或超过 24 小时时的一些警报消息。

我的部分代码用于查找所需事件

left_less_than_24_hours_to_event = full_events_room.select{ |event| Time.now < Time.parse(event['event_time']) && Time.parse(event['event_time']) < (Time.now + 24.hours) }
left_more_than_24_hours_to_event = full_events_room.select{ |event| (Time.now + 24.hours) < Time.parse(event['event_time']) }

并有一些黄瓜场景(快速翻译成英语(但语言无关紧要))

Сценарий: User came in 2019-10-15 12:00
Допустим current date is "2019-10-15 12:00"
И go to root page
То see red message "Event Lesson-41 without room to Python-2 group"
И time return

我在我的场景中尝试 binding.pry 并且有我真正需要的时间 In step definitions i have time which i needed

但与此同时,我在控制器中绑定.pry 我的端点操作,并再次使用我的系统! Screenshot with time

也许我做错了什么?或者我如何同时测试有关时间和浏览器输出的信息,例如警报(引导)消息?

这就是步骤定义中发生的事情

Допустим /^current date is "([^"]*)"/ do |date|
 time_to_travel = Time.parse(date)
 Timecop.travel(time_to_travel)
end

И /^time return/ do
  Timecop.return
end

【问题讨论】:

  • 从您的示例中不清楚,但您是否在任何地方接受/使用浏览器时间? Timecop 只会影响您的服务器时间,并且仅当您让 Capybara 在同一进程中运行应用程序和测试时。如果您也需要模拟浏览器时间,则需要寻找一个 JS 库来执行此操作,例如 sinon.js 等。

标签: ruby-on-rails ruby cucumber capybara timecop


【解决方案1】:

您是否在规范中尝试过 travel_to 助手?

您说您正在使用 Timecop,但没有附加任何示例。

来自 Andy Croll 的Here is a nice article 关于从 Timecop 迁移到内置助手

【讨论】:

  • travel_to 是我首先尝试做的,我什么都没有,在我尝试使用 Timecop gem 之后
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-18
  • 1970-01-01
  • 2012-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多