rspec

How to test controllers with nested routes using rspec

送分小仙女□ 提交于 2020-02-20 06:45:27
问题 I create controller with InherritedResource class AppsController < InheritedResources::Base belongs_to :company # Devise before_filter :login_or_oauth_required # CanCan load_and_authorize_resource end and try to test it with Rspec by this method require "spec_helper" include Devise::TestHelpers describe AppsController do before(:each) do @company_1 = Factory.build(:company) application_1 = Factory.create(:application, :company => @company_1) application_2 = Factory.create(:application,

How can I test ActionCable using RSpec?

心已入冬 提交于 2020-02-06 07:34:11
问题 This is my NotificationChannel class NotificationChannel < ApplicationCable::Channel def subscribed stream_from "notification_user_#{user.id}" end def unsubscribed stop_all_streams end end How can I write test for this ActionCable channels This is my Rspec require 'rails_helper' require_relative 'stubs/test_connection' RSpec.describe NotificationChannel, type: :channel do before do @user = create(:user) @connection = TestConnection.new(@user) @channel = NotificationChannel.new @connection, {}

rspec-rails and using let leading to variable conflicts?

巧了我就是萌 提交于 2020-02-05 06:43:47
问题 Was writing some tests and ran into an issue with using let to define some variables. I spent some time producing a minimal failing example: 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 1" do

rspec-rails and using let leading to variable conflicts?

你。 提交于 2020-02-05 06:43:03
问题 Was writing some tests and ran into an issue with using let to define some variables. I spent some time producing a minimal failing example: 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 1" do

Deprecation warnings after switching to the webdrivers gem

依然范特西╮ 提交于 2020-02-01 09:55:48
问题 As suggested here, I have replaced chromedriver-helper with webdrivers on a Rails 5.2 app with RSpec 3.8. According to this post, it should a simple replacement and after updating my Gemfile the specs work. However, I get a bunch of deprecation warnings 2019-04-23 13:33:02 WARN Selenium [DEPRECATION] Selenium::WebDriver::Error::UnhandledError is deprecated. Use Selenium::WebDriver::Error::UnknownError (ensure the driver supports W3C WebDriver specification) instead. 2019-04-23 13:33:02 WARN

Is there a way to check whether a method is stubbed with RSpec?

雨燕双飞 提交于 2020-02-01 06:20:46
问题 Mainly for test debugging purposes, I would like to know whether there is a way to tell whether a method is stubbed or not. For example, in one of my tests, I write: Model.any_instance.stub(:method) And when I have a real instance I want to write something like: an_instance_of_model.stubbed?(:method) # expecting to return true 回答1: In case you have stubbed the method in class level with the any_instance method you may check this using something like this in your test: RSpec::Mocks.any

Displaying unix color on windows cmd (e.g. ←[31m)

时间秒杀一切 提交于 2020-01-31 08:53:18
问题 I've recently started doing some ruby on rails development on Windows 7 and have found a number of commands (rspec, guard, etc) output colour codes that just show up in text on the windows command line (or through Console2 which I use). eg: ←[31mrspec ./spec/views/users/index.html.erb_spec.rb:21←[0m ←[36m# users/index renders a list of users←[0m ←[31mrspec ./spec/requests/homes_spec.rb:9←[0m ←[36m# Homes GET /homes ←[0m ←[31mrspec ./spec/views/users/new.html.erb_spec.rb:13←[0m ←[36m# users

Displaying unix color on windows cmd (e.g. ←[31m)

…衆ロ難τιáo~ 提交于 2020-01-31 08:51:32
问题 I've recently started doing some ruby on rails development on Windows 7 and have found a number of commands (rspec, guard, etc) output colour codes that just show up in text on the windows command line (or through Console2 which I use). eg: ←[31mrspec ./spec/views/users/index.html.erb_spec.rb:21←[0m ←[36m# users/index renders a list of users←[0m ←[31mrspec ./spec/requests/homes_spec.rb:9←[0m ←[36m# Homes GET /homes ←[0m ←[31mrspec ./spec/views/users/new.html.erb_spec.rb:13←[0m ←[36m# users

Disabling JavaScript when using Capybara + Selenium

回眸只為那壹抹淺笑 提交于 2020-01-29 17:45:26
问题 I have an app that's designed to still be functional when JavaScript is disabled, so I wanted to write some specs that covered those cases. I'm using Selenium (Firefox) with Capybara and I'm registering an new driver with JavaScript disabled (via Selenium's javascript.enabled property) # spec/rails_helper.rb Capybara.configure do |config| config.ignore_hidden_elements = true config.default_driver = :selenium end Capybara.register_driver :disable_js do |app| profile = Selenium::WebDriver:

testing routes with subdomain constraints using rspec

◇◆丶佛笑我妖孽 提交于 2020-01-29 04:54:20
问题 I'm having trouble getting my rspec routing tests working with a subdomain constraint. Specifically I have a route constraints :subdomain => "api" do resources :sign_ups, :only => [:create] end and (among others) a test it "does allow creation of sign ups" do {:post => "/sign_ups"}.should route_to( :controller => "sign_ups", :action => "create", ) end If I remove the subdomain constraint this test passes, but with it it fails. I have to tell rspec to use the subdomain but I'm at a loss as to