测试 使用 Cucumber 测试 API 的时候遇到问题

541991a · 2015年04月16日 · 最后由 541991a 回复于 2015年04月16日 · 1969 次阅读

遇到的错误: 我在 features/step_definitions/xxx_step.rb 中对某个 grape api 进行了 put 请求:

@response = put "/api/v1/users/profile"

于是跑 cucumber 测试的时候会报 ruby 解释器的错误

......

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

经过 debug 发现是由于在 api 的 controller 中调用的 helper 方法里面存在含有 '!'的代码,类似于

# users.rb
put :profile do
    ....
    do_some_thing
    ...
end

# helper.rb
def do_some_thing

    if !user.verify_email?
        ....    
    end

    # 或者

    run_something!

end

在 helper 方法里面只要存在'!'就会报错,而转移到 controller 中则没有问题,请问这是我自身的问题,还是 cucumber 的 bug 呢?有没有人也遇到过?

环境版本

  • osx 10.10.3
  • Ruby 2.1.2
  • Rails 4.2.0
  • Grape 0.11.0
  • Cucumber 1.3.19

你的第二行里:

我在 features/step_definitions/xxx_step.rb 中某个 grape api 进行了 put 请求

这个 字怎么打出来的,比 多了一个小点

是不是你的输入法问题?

#1 楼 @dddd1919 输入法的问题,已修改,多谢指出!

#3 楼 @541991a 我的意思是 bug 是不是也是因为输入法的问题

#4 楼 @dddd1919 这个我也考虑过,不过应该不是,在外层写可以,写 helper 方法里面就不行,感叹号是一起复制的。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号