Tag: rspec

尝试创建cookie时未定义的方法`permanent’

我创建了一个模块,因此我可以快速创建用户,以用户身份登录,删除用户并注销用户。 这是一个简化的例子: module UserAuth def sign_in(user) cookies.permanent[:remember_token] = ‘asda’ end end 但是,如果我运行此规范: describe ‘UserAuth’ do include UserAuth context ‘signed up’ do let(:user_1) { FactoryGirl.build(:user) } before { sign_up user_1 } contex ‘signed in’ do before { sign_in user_1 } it {} end end end 我收到此错误: undefined method `permanent’ for # 我觉得奇怪的是, cookies对象是可用的,但这种permanent方法不是出于某种原因。 我可以通过在UserAuth模块中包含另一个模块来解决此问题吗? 如果是这样,这个模块的名称是什么?

我怎样才能选择模拟地理编码器?

我希望能够在我的一些测试中模拟地理编码器 gem的结果。 我使用RSpec和Cucumber。 在黄瓜中,我想默认模仿Geocoder结果,但是可以通过添加标签再次打开它。 那将是完美的! RSpec类似的东西也会很好。 它会极大地加速我的测试。 我知道有一些gem用于做类似的事情,例如太阳黑子的 sunspot_test 。 地理编码器有类似的东西吗?

button_to表单提交在浏览器中工作但是没有rspec / capybara测试,路由错误

我正在使用rspec和capybara编写集成测试,用于覆盖现有function的rails4应用程序(当我第一次编写应用程序时,我很懒)。 以下提交按钮在浏览器(Chrome)中正常工作,并重定向到成功页面(如预期的那样) “open-contacts-dialog-btn”, :class => “inbox-sf-add-btn tip”, :style => “background:lightgreen” %> 但是,以下测试失败, describe “should show confirmation message after submitting the form” do it “should go to success message when form submitted” do click_link ‘See more details’ click_button ‘Sign Me Up!’ fill_in ‘Email’, with: “simon@example.com” fill_in ‘attendee_name’, with: “Simon T” fill_in ‘attendee_phone’, with: “1234567890” fill_in ‘attendee_num_guests’, […]

RailsTutorial 3.2 Ch 9 – “before {valid_signin(user)}”导致RSpec测试失败

我目前在RailsTutorial 3.2, 第9.3.1节用户索引中 。 代码清单9.27指向spec/requests/authentication_pages_spec.rb代码的编辑,如下所示: require ‘spec_helper’ describe “Authentication” do . . . describe “with valid information” do let(:user) { FactoryGirl.create(:user) } before { valid_signin(user) } it { should have_selector(‘title’, text: user.name) } it { should have_link(‘Users’, href: users_path) } it { should have_link(‘Profile’, href: user_path(user)) } it { should have_link(‘Settings’, href: edit_user_path(user)) } it […]

cabybara-webkit + rspec:记录不可用

我是集成测试的新手,虽然我已经为我的模型和控制器做了很多unit testing。 但现在我想测试整个堆栈。 (我不想使用Cucumber,因为没有客户,我可以阅读代码) 这是我的(简化)规范 describe ArticlesController, “#show” do before do @article = Factory :article, :title => “Lorem ipsum” end it “should show the article page” do visit article_path(:id => @article) page.should have_content(“Lorem ipsum”) end end 规范通过了,但是一旦我添加:js => true , it “should show the article page”, :js => true do ,抛出一个ActiveRecord::RecordNotFound 。 如果我在我的配置中禁用use_transactional_fixtures ,它会再次起作用,但这会打破很多其他测试。 是否有另一种解决方案或者我可以为我的集成测试禁用transactional_fixtures吗? […]

测试保持与Rspec签署

我有点难以为你所看到的“保持登录”function写一些rspec测试(以及在哪里),包括google登录。 我在网上找到的例子没什么帮助。 具体来说,我想测试这两种情况。 1 a)用户使用有效凭据登录而未点击“保持登录状态” b)用户关闭浏览器,重新打开它并请求保护页面。 用户不应该看到受保护的页面。 用户应该看到要求他们登录的页面。 2 a)用户使用有效凭据登录并点击“保持登录状态” b)用户关闭浏览器,重新打开它并请求受保护的页面。 用户不应该看到要求他们登录的页面。 应将用户带到受保护的页面。 我第一次尝试解决问题涉及通过删除我存储在会话中的user_id来模拟浏览器关闭(因为它在浏览器关闭时被删除)。 但是,这些测试失败了,因为我在请求规范文件夹中工作,并且无法访问会话变量。 我之前的相关问题: 某些rspec文件中的会话可用,而其他文件中没有。 怎么会? 使用rspec进行这些测试的最佳方法是什么?

rspec-rails和使用let导致变量冲突?

正在编写一些测试并遇到使用let来定义一些变量的问题。 我花了一些时间制作一个最小的失败例子: require “spec_helper” describe “Some behavior” do let(:attachments_dir) { “some_test_dir” } before :all do attachments_dir # Commenting out this line makes the tests pass end context “nested 1” do let(:api_params) do { message: { to: “recipient1”, from: “sender1”} } end before do puts “nested 1 before ” + api_params.to_s end it “nested 1 example […]

Rspec视图测试不会呈现更改

我正在使用rspec测试我的rails 3.2应用程序中的视图。 我已经为我的视图编写了测试以包含一些额外的输入字段,并且它们正确地失败了。 但是,在添加所需的输入字段后,测试仍然以相同的方式失败。 他们在终端输出表格,就好像我没有在视图中改变任何东西。 在浏览器中检查视图时,实际上存在字段,因此测试应该通过。 rspec没有加载最新的观点? 这是一些代码(我将它缩减为两个字段): it “renders the form to sign up” do rendered.should have_selector(“form”, action: “/users”, method: “post”) do |form| form.should have_selector(“input#user_email”, name: “user[email]”, type: “email”) form.should have_selector(“input#user_city”, name: “user[city]”, type: “text”) end end 电子邮件输入是我以前的旧输入,它确实识别它。 城市输入是新的,甚至不会出现在终端的视图输出中。 我究竟做错了什么?

在窗口中运行rspec时出错:找不到Webpack binstubs

当我运行rspec我收到以下错误: C:\Users\Chloe\workspace\catalyst_research>rspec Randomized with seed 41345 FFFFFFF……………………….FFFFFFFC:/ruby24/lib/ruby/gems/2.4.0/gems/webpacker-2.0/lib/tasks/installers.rake:1: warning: already initialized constant INSTALLERS C:/ruby24/lib/ruby/gems/2.4.0/gems/webpacker-2.0/lib/tasks/installers.rake:1: warning: previous definition of INSTALLERS was here C:/ruby24/lib/ruby/gems/2.4.0/gems/webpacker-2.0/lib/tasks/webpacker/install.rake:1: warning: already initialized constant WEBPACKER_APP_TEMPLATE_PATH C:/ruby24/lib/ruby/gems/2.4.0/gems/webpacker-2.0/lib/tasks/webpacker/install.rake:1: warning: previous definition of WEBPACKER_APP_TEMPLATE_PATH was here C:/Users/Chloe/workspace/catalyst_research/lib/tasks/test.rake:6: warning: already initialized constant DRIVERS C:/Users/Chloe/workspace/catalyst_research/lib/tasks/test.rake:6: warning: previous definition of DRIVERS was here Webpack binstubs not found. Make sure the […]

测试Devise正在后台工作人员中重新发送确认指示电子邮件

如果他们在注册后的两天内没有确认,我想第二次向用户发送Devise确认说明,但是我似乎无法通过我的成功案例测试。 背景工作者(每天运行一次): class ResendConfirmationWorker include Sidekiq::Worker sidekiq_options queue: :resend_confirmation, retry: false def perform d = Time.zone.now – 2.days users = User.where.not(confirmation_sent_at: nil) .where(confirmed_at: nil) .where(created_at: d.beginning_of_day..d.end_of_day) users.find_each do |user| user.send_confirmation_instructions end end end RSpec测试: require ‘rails_helper’ describe ResendConfirmationWorker, type: :job do before do time = Time.zone.now – 2.days @user = create :unconfirmed_user, created_at: time, confirmation_sent_at: […]