有没有办法在 RSpec 配置块中包含所有辅助模块?
Is there a way to include all helper modules in RSpec configure block?
我的 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
我的 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