Tag: 水豚

Rspec / Capybara:测试是否调用控制器方法

鉴于我设置了一个带有索引动作的HomeController class HomeController < ApplicationController def index @users = User.all end end 并通过根路径路由到它, root :to => “home#index” 为什么这个请求规范失败了 it ‘should called the home#index action’ do HomeController.should_receive(:index) visit root_path end 以下消息 Failure/Error: HomeController.should_receive(:index) ().index(any args) expected: 1 time received: 0 times ? 是因为索引方法被调用为实例方法而不是类方法?

使用水豚时路径不能正常工作

我正在使用rails 3.0.5,rspec2和最新的capybara。 路线设置如下: scope “(:locale)”, :locale => /de|fr|it|en/ do resources :dossiers end 在application_controller我有这个: def default_url_options(options={}) options[:locale] = “es” options end 所以在我看来我可以使用 link_to ‘test’, dossier_path(1) 没有任何问题。 但是当我在capybara的访问中做同样的事情时,它会尝试使用1作为语言环境而不是id。 它只在我使用时才有效 visit dossier_path(nil, 1) 要么 visit dossier_path(:id => 1) 但两者都是丑陋的,看起来像一个肮脏的黑客。 那么为什么我需要使用这个脏的hack以及我要做什么,以便我可以像在视图中一样使用路径方法(所以没有必须添加nil或显式传递的脏黑客:id =>。 ..)? 🙂

使用FactoryGirl创建的记录在Controller中不可用

我的一项测试已经开始失败。 它以前工作并在浏览器中手动执行相同的操作显示该function正在工作。 我创建了要测试的记录,如下所示: will = FactoryGirl.create(:user, profile: “security of the internet”, first_name: “will”) 为了调查,我添加了一个 binding.pry 打电话到我的控制器。 该操作搜索用户。 如果我做: User.all 在pry提示符下,没有显示用户,结果为空。 如果我用pry进入实际测试,User.all会显示预期的记录。 可能是什么原因造成的?

如何测试发布请求并跟随capybara重定向?

我正在尝试用水豚和黄瓜测试一个post请求。 我无法访问页面并按下链接发送请求,因为它有一个确认对话框,我没有使用javascript工作,所以我试图使用post方法,然后测试它是否重定向到适当的url但是我得到了: No response yet. Request a page first. (Rack::Test::Error) 我的代码是: page.driver.post url page.driver.status_code.should be 302 follow_redirect! 它一直很好,直到follow_redirect! 。 我试过了page.driver.follow_redirects! 但它也不起作用。 有帮助吗?

Capybara电子邮件重置会话

我需要在注册Capybara后测试一个特定的智能重定向流程。 假设我的网站上有几个interesting_pages ,我希望在确认注册后将用户重定向到上次访问过的有趣页面 小场景: When I visit the interesting page “42” And I visit a couple uninteresting pages # Note during the visit to other pages, session[:interesting_page] is correctly set to the url of page “42” When I sign up and I confirm via the link in the email # At this point I have […]

capybara:post,在将请求名称的目录更改为function时获取方法不起作用

升级到Capybara的最新版本后,我的所有访问方法都停止了工作,所以我按照一些人提出的解决方案将请求spec目录重命名为“features”。 现在我的访问方法再次起作用,但请求规范中的任何get或post方法都会导致此错误: undefined method `get’ for # 这是触发错误的代码: describe “getting posts” do before { get(forum_posts_path) } it “should respond with a 200” do response.response_code.should == 200 end end 对此有何解决方法?

rails3.2 + rspec + capybara1.0测试设计google-oauth2.0

我正在使用带有ruby1.9.2导轨的capybara 1.0 3.2这是我的测试: #spec/features/google_login_spec.rb require ‘spec_helper’ describe “the signin process”, type: :feature do before do puts user_omniauth_authorize_path(:google_oauth2) #/users/auth/google_oauth2 visit user_omniauth_authorize_path(:google_oauth2) end it {#somethings} end 但我有这个错误: Failures: 1) the signin process Failure/Error: visit user_omniauth_authorize_path(:google_oauth2) ActionController::RoutingError: No route matches [GET] “/o/oauth2/auth” # ./spec/features/google_login_spec.rb:9:in `block (2 levels) in ‘ 我的路线文件就是这个 #config/routes.rb Booking::Application.routes.draw do #https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview#using-omniauth-without-other-authentications devise_for :users , controllers: […]

Capybara如何在没有id的页面中使用within_frame作为唯一的iframe

我在需要使用Cucumber和Capybara测试的页面中有一个iframe,iframe没有class或id属性,但它是DOM上唯一的iframe。 我如何使用within_frame方法?

使用Capybara检查多个页面上的页面响应

我正在使用带有Ruby on Rails的Capybara来创建一个集成测试,它将填充所有字段并提交表单。 然后,这将加载一个新页面到浏览器。 是否有可能在测试中获得第二页的响应? describe “the signup process”, :type => :request do it “signs me in” do visit sign_up_path fill_in ‘user_first_name’, :with => “Jhonny” t1 = Time.new fill_in ‘user_email’, :with => “joe412@offerslot.com” fill_in ‘user_last_name’, :with => “Bravo” fill_in ‘user_zip_code’, :with => “94102” fill_in ‘user_password’, :with => “password1234” click_button ‘user-button’ response.should be_success response.body should_contain(“Text on […]

黄瓜水豚茬

我在一个名为images_controller.rb的rails控制器中有一个索引操作,它从外部服务中获取图像。 我正在尝试编写黄瓜场景,并且正在努力解决如何编写/存根我的访问索引页面步骤。 如果不提出请求,我怎么能将它取出的图像存根? 特征: Scenario: Image Index Given an image exists on the image server When I am on the images page Then I should see images 目前为止的步骤: Given(/^an image exists on the image server$/) do image_server_url = IMAGE_SERVER[‘base_url’] + “/all_images” image = “image.png” image_path = “development_can/image.png” response = [{image_path => [image]}].to_json stub_request(:get, image_server_url).to_return(JSON.parse(response)) end […]