rspec-rails

Sending an email with Sidekiq RSpec Test failed because Array is empty and could not change from 0 to 1

*爱你&永不变心* 提交于 2021-01-29 02:58:57
问题 I am trying to test sending an email with Sidekiq and I am having an error which means it doesn't enqueue since my test shows it didn't change from 0 to 1 in size. Could it be I am missing something out or how can I fix this? Error expected `Array#size` to have changed by 1, but was changed by 0 0) Sending Mail sends email to sidekiq Failure/Error: expect do OrderPointsMailer.paid_order_email(customer_detail.id).deliver_later end.to change(Sidekiq::Worker.jobs, :size).by(1) expected `Array

Rspec: Test rescue block

ε祈祈猫儿з 提交于 2021-01-28 18:24:05
问题 I have a block like this: begin response = Facebook.make_profile_request(params[:token]) rescue => e Airbrake.notify( :error_class => "Facebook Processing", :error_message => "Error: #{e.message}" ) flash[:notice] = "Uh oh...something went wrong. Please try again." redirect_to root_path end This is what I have so far: it "should notify Airbrake if call to FB fails" do Facebook.stub(:make_profile_request).with(fb_token).and_raise(Exception) Airbrake.should_receive(:notify) get :facebook

How to properly mock itnernal services in RSpec?

混江龙づ霸主 提交于 2021-01-28 14:41:36
问题 I would like to learn how to properly mock object calls inside other classes, foor example I have this controller action: def show service = Action::PartsShow.new(show_params, current_user) service.call render json: service.part, root: :part, serializer: PartSerializer, include: '**', scope: {current_user: current_user} end The service class looks like this. module Action class PartsShow < PartsShowBase def find_part ... end end end module Action class PartsShowBase attr_reader :part def

How to properly mock itnernal services in RSpec?

我是研究僧i 提交于 2021-01-28 14:35:27
问题 I would like to learn how to properly mock object calls inside other classes, foor example I have this controller action: def show service = Action::PartsShow.new(show_params, current_user) service.call render json: service.part, root: :part, serializer: PartSerializer, include: '**', scope: {current_user: current_user} end The service class looks like this. module Action class PartsShow < PartsShowBase def find_part ... end end end module Action class PartsShowBase attr_reader :part def

How can I add a function to FactoryBot globally?

落爺英雄遲暮 提交于 2021-01-28 11:00:51
问题 I have a class that extends FactoryBot to include functionality to copy Rails' .first_or_create . module FactoryBotFirstOrCreate def first(type, args) klass = type.to_s.camelize.constantize conditions = args.first.is_a?(Symbol) ? args[1] : args[0] if !conditions.empty? && conditions.is_a?(Hash) klass.where(conditions).first end end def first_or_create(type, *args) first(type, args) || create(type, *args) end def first_or_build(type, *args) first(type, args) || build(type, *args) end end I can

Problems upgrading Rails 4.0.0 to 4.0.x (4.0.13) - private method `include' called for ActionDispatch::Assertions:Module (NoMethodError)

試著忘記壹切 提交于 2021-01-28 05:11:13
问题 I could not find a "direct" answer to this anywhere. Since I know there will be many other "Late Upgraders" to the party, I feel I need to get this out. I had a Rails 4.0.0 app running Ruby 2.0.0-p247. After upgrading to 4.0.13, I ran into this error: private method `include' called for ActionDispatch::Assertions:Module (NoMethodError) I received this through rspec and WEBrick. 回答1: I found a solution via another issue from layer-ruby: NoMethodError: private method `include' called for #

how to check array changes in rspec after a service call?

风格不统一 提交于 2020-07-09 05:22:18
问题 The goal is simple example we have an array [ {name: "ghost", state: "rejected"}, {name: "donkey", state: "rejected"} ] After running the Service call UpdateAllUsers , it would change all the users to 'accepted' [ {name: "ghost", state: "accepted"}, {name: "donkey", state: "accepted"} ] The question here is how do i check all the object in the array to have the same value after that service call in rspec? example in rspec describe 'call' do let(:all_users) { build(:users, 2, state: "rejected"

How to run multiple spec files in RSpec using single command in terminal?

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-17 01:38:29
问题 I need to run RSpec at one go for multiple files of my choice can anyone guide me through it? I am a beginner so please explain clearly 回答1: Yes, you can. For multiple files without a pattern You can use the following syntax to run your specs for multiple files: rspec path/to/first/file path/to/second/file Multiple files with pattern If you wish to run spec from some specific folders then you might use rspec --pattern=./spec/features/**/*_spec.rb If you want to exclude some files rspec -

How to properly test ActiveJob's retry_on method with rspec?

此生再无相见时 提交于 2020-05-14 14:57:29
问题 I have been attempting to test this method for the past few days with no luck. Another thing I'd like to be able to do is rescue the error that bubbles up after the final retry attempt is made. Please see my comments and code snippets below. Source code for retry_on is here as well for context. Here's the sample code and tests: my_job.rb retry_on Exception, wait: 2.hours, attempts: 3 do |job, exception| # some kind of rescue here after job.exceptions == 3 # then notify Bugsnag of failed final

How to find a variable with rspec tests using page.find

蓝咒 提交于 2020-03-15 11:50:29
问题 I have a test case, most of my other pages have at least one field that is just straight text and can be found using: page.find("tr", text: "What I filled in").find("a.tick").click This page all of the options are drop down selects, so how do I find a variable? The rest of the syntax looks like this: it "edits person job and redirects to index" do expect(p = FactoryGirl.create(:person)).to be_valid() expect(j = FactoryGirl.create(:job)).to be_valid() visit new_job_path select p.name, from: