rspec

Testing helper in rspec with I18n lazy lookup

血红的双手。 提交于 2019-12-23 12:07:15
问题 Consider this example. I have a Product model which has discount_percentage . And we're maintaining multiple locales. In the view we do not want the i18n stuff mess up the view. So we make a helper to read better and probably reuse it in other views: render_product_discount (code please see below) which will render the discount status of this product. And we use i18n lazy lookup feature throughout the application. But when we want to test this helper method we get a Error: # RuntimeError: #

How to disable a before_action in a controller spec?

社会主义新天地 提交于 2019-12-23 12:02:05
问题 I've employed the use of this in my controller spec: controller.class.skip_before_action Specifically, in this case: controller.class.skip_before_action :require_authorisation_to_view_materials MaterialsController: class MaterialsController < ApplicationController before_action :set_material, only: [:show, :edit, :update, :destroy] before_action :require_authorisation_to_view_materials, only: [:index, :show] def require_authorisation_to_view_materials # For Materials Page unless user_signed

using rails.vim Rake run spec in MacVim, how to get colored output

陌路散爱 提交于 2019-12-23 10:54:28
问题 when using Rake to run a spec, the output in quickfix is not colored, meaning, it doesn't have green for passing specs and red for failing specs. Is this something solvable? Thanks for any hints. 回答1: According to Tim Pope, the author of rails.vim, not much that can be done about that; Vim doesn't support ANSI color codes. 回答2: It may be possible by recompiling vim as this plugin suggest. I haven't tried it myself. http://www.vim.org/scripts/script.php?script_id=302 来源: https://stackoverflow

Can't get RSpec to work — 'require': cannot load such file

会有一股神秘感。 提交于 2019-12-23 09:59:37
问题 I just spent three days of my life banging my head against the wall trying to figure out why a simple 'rake' would not pass my spec file. If this happens to you: Do not have a space in any folder path!. Seriously. In fact do not have a space in anything you name from here on out. Here is my console output: (in /Users/*****/Desktop/Learning Ruby/learn_ruby ) $ rake /Users/*******/Desktop/Learning Ruby/learn_ruby/00_hello/hello_spec.rb:116: in `require': cannot load such file -- hello

How to click radio button with capybara in ruby on rails app

醉酒当歌 提交于 2019-12-23 09:41:10
问题 I'm trying to select a radio button with capybara and it can't find the radio button. Here is my rspec test, view and error. Please note that I am using factories for user, skills, etc. Rspec test scenario "user chooses a couple skills and moves on to bio" do user = create(:user) skill = create(:skill) skill_two = create(:skill) skill_three = create(:skill) sign_in(user) visit onboard_skills_path choose(skill.name) end View <%= form_for(:onboard_skill, url: onboard_skills_path) do |f| %> <ul>

Why does Rails RSpec response show 302 instead of 401?

寵の児 提交于 2019-12-23 09:32:13
问题 I have been stuck on this problem for several days and I don't know what is wrong with it. I started Ruby on Rails few months ago and I am currently learning authentication with API. I have looked at other similar topics here and there but none of them helped. My problem is whenever I run RSpec on this code (located at spec/api/v1/controllers/posts_controller_spec.rb ) require 'rails_helper' RSpec.describe Api::V1::PostsController, type: :controller do let(:my_user) { create(:user) } let(:my

Devise Rspec registration controller test failing on update as if it was trying to confirm email address

不羁的心 提交于 2019-12-23 09:22:23
问题 I have the following route: devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => 'users/registrations', :sessions => "users/sessions" } and the following controller test (registrations_controller_spec.rb): require File.dirname(__FILE__) + '/../spec_helper' describe Users::RegistrationsController do include Devise::TestHelpers fixtures :all render_views before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] end describe

How do I test mandrill api with rspec

我只是一个虾纸丫 提交于 2019-12-23 08:30:06
问题 So my client has reported that many of the emails are going to the wrong person, and I would like to write some feature tests to find and make sure that they are receiving the email and what it says in my specs. I have mandrill_mailer which uses mandril api, and before it sends out I would like to see what the message is. For example. Create a new user account -> creates the user, and then sends out a welcome email. in devise it calls RegistrationMailer.new_registration(resource).deliver

How do I test mandrill api with rspec

拜拜、爱过 提交于 2019-12-23 08:30:04
问题 So my client has reported that many of the emails are going to the wrong person, and I would like to write some feature tests to find and make sure that they are receiving the email and what it says in my specs. I have mandrill_mailer which uses mandril api, and before it sends out I would like to see what the message is. For example. Create a new user account -> creates the user, and then sends out a welcome email. in devise it calls RegistrationMailer.new_registration(resource).deliver

rspec rails testing: how can I force ActiveJob job's to run inline for certain tests?

喜你入骨 提交于 2019-12-23 08:06:34
问题 I would like my background jobs to run inline for certain marked tests. I can do it by wrapping the test with perform_enqueued do but I'd like to just be able to tag them with metadata and it happens automatically, if possible. I've tried the following: it "does everything in the job too", perform_enqueued: true do end config.around(:each) do |example| if example.metadata[:perform_enqueued] perform_enqueued_jobs do example.run end end end but it results in an error: undefined method `perform