无法使用 Capybara,不确定我哪里出错了 'background' 和 'it' 等不工作

Unable to use Capybara, Not sure where I am going wrong 'background' and 'it' etc is not working

您好,我正在学习水豚,我已经尝试了各种答案,所以我无法继续。我正在尝试使用水豚测试应用程序。访问不工作,错误说它需要在 'it' 或 example/executable 块内等。但是下面的代码、背景和场景等不工作,执行不在里面。

结果::

C:\Ruby223\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load([=12=]=ARGV.shift) C:/Users/xxx/RubymineProjects/xxx-app/spec/features/xxxxx.rb
"aaa"

Process finished with exit code 0

我不想弄乱 Rails 应用程序,所以我想要一个独立的文件,我可以从中执行测试,然后在开发人员的帮助下与 rails 应用程序集成。

require 'capybara/dsl'
require 'capybara'
require 'capybara/rspec'
require 'rspec'



feature "Signing in" do
  p 'aaa'
  background do
    p 'aaa1'
    Capybara.register_driver :selenium_chrome do |app|
      Capybara::Selenium::Driver.new(app, :browser => :chrome)
    end
    Capybara.run_server = false
    Capybara.current_driver = :selenium_chrome
    Capybara.app_host = 'http://www.google.com'
  end

  scenario "Signing in with correct credentials" do
    p 'aaa2'
    visit '/q=?alkjaaa'
    within("#session") do
      fill_in 'email', with: 'user@example.com'
      fill_in 'password', with: 'caplin'
    end
    click_button 'Signin'
    expect(page).to have_content 'results'
  end

  given(:other_user) { User.make(email: 'other@example.com', password: 'rous') }

  scenario "Signing in as another user" do
    p 'aaa'
    visit '/sessions/new'
    within("#session") do
      fill_in 'Email', with: other_user.email
      fill_in 'Password', with: other_user.password
    end
    click_button 'Signin'
    expect(page).to have_content 'Invalid email or password'
  end
end

运行 单独使用 ruby 的文件不会做任何事情,因为它所做的只是定义测试,而不是执行它们。如果您 运行 该文件带有 rspec 那么它将 运行 文件中定义的测试。

rspec your_file.rb