gpt4 book ai didi

javascript - 创建插件时如何让 Capybara 在插件目录中看到 Javascript?

转载 作者:数据小太阳 更新时间:2023-10-29 07:37:07 24 4
gpt4 key购买 nike

我们正在为 Rails 开发一个插件,我已经让 Cucumber 与 Capybara 完美配合。但是,在开发时,我一直(我猜是错误的)将 Javascript 文件放在父测试应用程序的 public/javascript 目录中。所以当 Capybara 运行时,它找不到 javascript 文件。我们怎样才能让 Cucumber/Capybara 看到那些 JS 文件?

更多细节:

因此布局“reports.html.haml”指的是“src='/javascripts/...'”但是当我从 vendor/plugins/reporter 目录中运行 cucumber 时,Capybara 找不到 JS 文件(我认为)。那么我应该从应用程序根目录运行 Cucumber 并包括插件的文件,还是我需要在其他地方包括 JS 文件(例如, vendor/插件/报告程序层次结构中的某处)?

这是我们当前的 PLUGIN 目录布局:

|~app/
| |~controllers/
| | `-reports_controller.rb
| |~models/
| | `-report.rb
| `~views/
| |~layouts/
| | `-reports.html.haml
| `~reports/
| |-edit.html.haml
| |-index.html.haml
| |-new.html.haml
| |-show.html.haml
| `-show.js.erb
|+autotest/
|+config/
|~features/
| |+step_definitions/
| |+support/
| `-reports.feature
|+generators/
|+lib/
|+spec/
|...

最佳答案

听起来您需要的是将插件构建为 Rails 引擎,这样您就可以将 javascript 放入插件中,但仍然可以从父应用程序访问它们。

这取 self 正在构建的具有类似要求的插件。要包含 javascript,您可以使用 javascript_include_tag 'my-plugin/javascripts/foo.js' 假设文件存在于 [plugin_path]/public/javascripts/foo.js

module MyPlugin
class Engine < Rails::Engine
config.mount_at = '/my-plugin/'

initializer "static assets" do |app|
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
end
end
end

关于javascript - 创建插件时如何让 Capybara 在插件目录中看到 Javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4023882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com