嗨,我正在学习水豚,我已经尝试了各种答案,所以我无法继续。我正试图用水豚测试一个应用程序。访问不起作用,错误说它需要在'它'或示例/可执行块等,但由于下面的代码,背景和场景等不起作用,执行不会进入。
结果::
C:\Ruby223\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/xxx/RubymineProjects/xxx-app/spec/features/xxxxx.rb
"aaa"
Process finished with exit code 0
我不想弄乱Rails应用程序,所以我想要一个独立的文件,我可以在那里执行测试,然后与开发人员帮助的rails app集成。
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
答案 0 :(得分:1)
单独使用ruby运行该文件并不会做任何事情,因为它所做的只是定义测试,它不会执行它们。如果您使用rspec运行该文件,那么它将运行文件中定义的测试。
rspec your_file.rb