我的RSpec配置块在我的spec_helper
中看起来像这样
RSpec.configure do |config|
config.include Capybara::DSL
config.include Helpers
config.include Helpers::CustomFinders
config.include Helpers::SignUp
...
end
我的助手文件看起来像这样:
module Helpers
module CustomFinders
# method defs here
end
module SignUp
# method defs here
end
# Other modules here
# Some other method defs here also
...
end
有没有一种方法可以简单地在一行中添加RSpec配置块中的所有模块?我的助手文件中有很多模块,并且必须继续向我的spec_helper添加任何新模块。
您可以重构Helpers
模块以自包含所有子模块,然后在Rspec中只需要包含Helpers
模块
module Helpers
def self.included(base)
base.include CustomFinders
base.include SignUp
end
module CustomFinders
# method defs here
end
module SignUp
# method defs here
end
# Other modules here
# Some other method defs here also
end
在spec_helper.rb
中
RSpec.configure do |config|
config.include Capybara::DSL
config.include Helpers
end