require 'test_helper'
class MyTest < ActionController::IntegrationTest
test "view posts from login page" do
visit("/logins/new")
find_field('Username').set('abode')
find_field('Password').set('efghi')
click_link_or_button('Login')
assert page.has_content?('Signed in!')
end
test "go to new user page" do
visit("/logins/new")
click_link("New user?")
assert (current_path == "/users/new")
end
end
Error:
test_view_posts_from_login_page(MyTest):
ActionController::RoutingError: No route matches [POST] "/logins/new"
test/integration/view_posts_test.rb:12:in `block in <class:MyTest>'
Run Code Online (Sandbox Code Playgroud)
它显示第 12 行的错误。按钮“登录”或 /logins/new 路径是否有问题?第二个测试通过了所以路径应该是正确的?我究竟做错了什么?
谢谢!
我是一个全新的人,我正在学习Ruby on Rails和Michael Hartl的教程.我在第3章,关于页面的Rspec测试失败(而完全相同的测试并没有失败的主页和帮助页面).
我在运行时遇到的错误$ bundle exec rspec spec/requests/static_pages_spec.rb是:
Failures:
1) Static pages About page should have the content 'About Us'?[31mFailure/Error:?[0m ?[31mvisit 'static_pages/about'?[0m?[31mURI::InvalidURIError?[0m:?[31mthe scheme http does not accept registry part: www.example.com:80static_pages (or bad hostname?)?[0m?[36m # ./spec/requests/static_pages_spec.rb:24:in `block (3 levels) in <top (required)>'?[0m Finished in 0.0776 seconds?[31m3 examples, 1 failure?[0m
Failed examples:
?[31mrspec ./spec/requests/static_pages_spec.rb:23?[0m ?[36m# Static pages About page should have the content 'About Us'?[0m
Run Code Online (Sandbox Code Playgroud)
当访问http://localhost:3000/static_pages/about页面加载时,我可以在大H1字母中看到"关于我们".
规格/请求/ static_pages_spec.rb:
require 'spec_helper'
describe "Static pages" do
describe "Home page" …Run Code Online (Sandbox Code Playgroud) 我有一个 Rails 应用程序,我正在尝试测试拖放功能,我正在使用 capybara 和 rspec 以及 jquery ui 进行拖动,它在浏览器中工作正常,但我无法进行工作测试它。我得到的错误如下:
source_element.drag_to(dest_element)
NotImplementedError: NotImplementedError
Run Code Online (Sandbox Code Playgroud)
我有一个简单的测试文件,如下所示:
describe "display index page" do
it "try drag and drop" do
dest_element = find('#list_'+list.id.to_s+' #sortable')
source_element = find('#list_'+other_list.id.to_s)
source_element.drag_to dest_element
end
end
Run Code Online (Sandbox Code Playgroud)
我的 Html 看起来像这样(javascript 配置正确并且一切都在浏览器中运行):
<ul id="sortable" class="ui-sortable">
<li id="list_20" class="sort">
<li id="list_121" class="sort">
<span>Content</span>
<ul id="sortable" class="ui-sortable"> </ul>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
谁能指出我可能出错的地方?我已经尝试环顾了好几个小时,但一直无法弄清楚解决方案是什么。
提前致谢
我是在 Rails 中测试的新手,我不明白为什么或何时应该使用夹具(或工厂),而不仅仅是为我的测试数据库播种并查询它来运行测试?
在许多情况下,在 dev 和 test env 中拥有相同的数据应该更快、更容易。
例如,如果我想测试一个索引页,我应该通过工厂创建 100 条记录还是应该用 100 条记录为数据库做种子?
我有人可以澄清这一点,这会很棒。
谢谢!
我正在尝试使用Capybara单击一个按钮.我尝试了所有我能想到的组合,但没有运气.试图点击"删除"链接.只有当您将鼠标悬停在表格中的行上时,才会显示删除链接.
这是HTML:
<tbody>
<tr class="even" id="informal_6">
<td class="columnOrganizationNameColumnValue" id="informal_7">
<div>
<a id="showLink_0" title="Organization Details" class="viewLink">
Institution / Automation
</a>
</div>
<div class="gridMenuDescription">
</div>
<div class="gridMenu">
<a id="gridMenuDirectLink_1" title="Edit Organization" class="gridMenuItem">
edit
</a>
<a id="gridMenuDirectLink_2" class="gridMenuItem delete">
delete
</a>
</div>
</td>
</tbody>
Run Code Online (Sandbox Code Playgroud)
我想注意一下,"gridMenu"div,当你使用Firebug将鼠标悬停在它上面时,它转向:
<div class="gridMenu hover gridMenuShow">
Run Code Online (Sandbox Code Playgroud)
我试过的一些事情,但没有运气:
find(:xpath, '//*[(@id = "gridMenuDirectLink_2")]').click
find("#informal_6").find("#informal_7").find(".gridMenu.hover.gridMenuShow").find(".gridMenuItem.delete").click
Run Code Online (Sandbox Code Playgroud)
建议?
我正在运行RSpec 3测试,并且在这个特定路径上遇到同样的错误:
Failure/Error: visit book_path
ActionController::UrlGenerationError:
No route matches {:action=>"show", :controller=>"books"} missing required keys: [:id]
Run Code Online (Sandbox Code Playgroud)
我的测试还没完成,所以我确定后面的一些代码可能不正确.但我无法让我的访问路径行运行:
...
book = FactoryGirl.build(:book)
reviews = FactoryGirl.build_list(:review, 5, book: book)
visit book_path
reviews.each do |review|
expect(page).to have_content(review.rating)
expect(page).to have_content(review.body)
expect(page).to have_content(review.timestamp)
end
expect(page).to have_content('House of Leaves')
expect(page).to have_content('Mark Z. Danielewski')
expect(page).to have_content('Horror')
end
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我将show定义为:
def show
@book = Book.find(params[:id])
@reviews = @book.reviews.order('created_at DESC')
@review = Review.new
end
Run Code Online (Sandbox Code Playgroud)
我的资源:
resources :books, only: [:index, :show, :new, :create] do
resources :reviews, only: [:show, :new, :create] do
end
Run Code Online (Sandbox Code Playgroud) 运行黄瓜场景时,我想在隐身模式下使用 Chrome。我尝试了通过互联网找到的一些建议,但似乎都不起作用。
目前,我想到了以下内容,它启动了 chrome,但不是在隐身模式下
Capybara.register_driver :selenium do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => %w["--incognito"]})
Capybara::Selenium::Driver.new(app, {:browser => :chrome, :desired_capabilities => caps})
end
Run Code Online (Sandbox Code Playgroud)
有小费吗?
NoMethodError: undefined method `color_enabled=' for #<RSpec::Core::Configuration:0x007ff1ba922ad0>
from /Users/apple/.rvm/gems/ruby-2.0.0-p247@global/gems/rspec-console-0.2.7/lib/rspec-console/config_cache.rb:69:in `method_missing'
Run Code Online (Sandbox Code Playgroud)
我不知道怎么解决它〜
有什么建议吗?THX〜
我有RSpec可安装的Rails引擎:
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Run Code Online (Sandbox Code Playgroud)
简单工厂:
FactoryGirl.define do
factory :post, :class => MyEngine::Post do
title 'title'
end
end
Run Code Online (Sandbox Code Playgroud)
水豚特色:
require 'spec_helper'
describe 'Post', :type => :feature do
let(:post) { FactoryGirl.create :post }
it 'index action should have post' do
visit posts_path
expect(page).to have_text(post.title)
end
end
Run Code Online (Sandbox Code Playgroud)
Post模型没有任何验证.
但是当我运行测试时,它表明没有创建帖子.
还有ActiveRecord日志:
INSERT INTO "my_engine_posts" ...
RELEASE SAVEPOINT active_record_1
rollback transaction
Run Code Online (Sandbox Code Playgroud) 在Capybara集成测试中取消选中复选框的正确方法是什么?我有一个复选框列表,我需要取消选中.我选择它们全部使用all:
checkboxes = all("input[type='checkbox']")
Run Code Online (Sandbox Code Playgroud)
为了取消选中我使用的每一个each.根据我在StackOverflow上找到的信息,取消选中一个复选框应该有三种方法:
uncheck(field)
field.click
field.set(false)
Run Code Online (Sandbox Code Playgroud)
为了测试这些不同的方法我是否创建了以下测试(每个测试都在同一页面的单独场景中):
使用uncheck它成功:
checkboxes = all("input[type='checkbox']")
checkboxes.each { |field| expect(field.checked?).to eq("checked") }
checkboxes.each { |field| uncheck(field[:id]) }
checkboxes.each { |field| expect(field.checked?).to eq(nil) }
puts page.body
save_and_open_page
Run Code Online (Sandbox Code Playgroud)
使用click它失败了,所以我认为这是取消选中该字段的不正确方法:
checkboxes = all("input[type='checkbox']")
checkboxes.each { |field| expect(field.checked?).to eq("checked") }
checkboxes.each { |field| field.click }
checkboxes.each { |field| expect(field.checked?).to eq(nil) }
puts page.body
save_and_open_page
Run Code Online (Sandbox Code Playgroud)
使用set(false)它成功:
checkboxes = all("input[type='checkbox']")
checkboxes.each { |field| expect(field.checked?).to eq("checked") }
checkboxes.each { |field| …Run Code Online (Sandbox Code Playgroud) capybara ×10
rspec ×5
factory-bot ×2
ruby ×2
checkbox ×1
cucumber ×1
jquery-ui ×1
rspec-rails ×1
simple-form ×1
testing ×1
xpath ×1