【问题标题】:can cucumber and rspec use the same blueprints.rb filecucumber 和 rspec 可以使用同一个 blueprints.rb 文件吗
【发布时间】:2011-03-06 05:55:15
【问题描述】:

我同时使用 Rails 3、机械师 2、黄瓜和 rspec,并且有两个 blueprints.rb 文件。一个在 spec 目录中,一个在 features/support 目录中。

只有一个 blueprints.rb 文件是个好主意吗?

如果是,首选的设置方式是什么?

与此同时,我只是将我的 features/support/blueprints.rb 文件符号链接到 spec/blueprints.rb 这可能不好,但它对我有用。

【问题讨论】:

    标签: ruby-on-rails rspec cucumber machinist


    【解决方案1】:

    我在功能/支持中有这个

    文件名 machinist.rb

    require 'machinist/active_record' 
    
    Dir[ File.dirname(__FILE__) + "/../../spec/blueprints/*"].each {|file| require file }
    
    Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
    

    【讨论】:

    • 如果我只需要 'require File.join(File.dirname(FILE), "..", "..", "spec ", "blueprints.rb")' 并删除 Sham.reset。
    【解决方案2】:

    这听起来很正常 - 我们为共享的固定装置和助手执行此操作(但我不使用机械师)。

    您可能需要做的是在您的黄瓜 env 和 rspec 帮助文件中包含这样的一行。这样做的目的是将包含 blueprints.rb 文件的目录放在 Ruby 包含文件时要查看的路径列表的顶部。

    $: << File.expand_path(File.join(File.dirname(__FILE__), "..","..","shared","directory"))
    #require 'blueprints' will now look in the above directory first
    

    "..","..","shared","directory" 部分是从当前文件到您的 blueprints.rb 文件所在的共享目录的相对路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 2013-05-24
      • 2011-12-28
      相关资源
      最近更新 更多