Questions tagged [rspec]

1

votes
2

answer
52

Views

rspec expect compare two hash that by excluding specified keys

Is there any spec expect which will compare two hashes by excluding specified keys alone. H1 = {'name' => 'XXXXx', 'age' => 29, 'DOB' => 'dd/mm/yyyy'} H2 = {'name' => 'XXXXX', 'age' => 29, 'DOB' => 'dd/mm/yyyy'} Compare the above two hashes by excluding DOB key alone.
Munish Prabhu
0

votes
0

answer
3

Views

Chain Multiple UI interactions using moxios

I have to test a scenario where I click on a selection in dropdown verify dom content then click on second selection in dropdown verify dom content and then click on first selection again and verify dom content I have been looking at moxios documentation and I have tried to wrap moxios.wait inside e...
Praveen Banthia
1

votes
2

answer
660

Views

How do I test a .sample method in rspec?

I am writing a test in rspec: it 'should choose a sign at random' do game.choose_sign expect(game.choose_sign).to eq 'rock' end ruby code: def choose_sign ['rock','paper','scissor'].sample end The code works but the test only passes when one of the values has been selected that matches whatever I pu...
enigma coder
1

votes
3

answer
196

Views

how to print current page response when using rspec

Eg. describe 'xxx' do let() {} print page.response before {visit user_path(user)} print page.response Is there any similar grammar to implement 'print page.response'? What's the correct way to debug when writing rspec?
makeapp
1

votes
3

answer
62

Views

How to assert that a method call was not made, without any_instance?

I have a class, that in one situation should call :my_method, but in another situation must not call method :my_method. I would like to test both cases. Also, I would like the test to document the cases when :my_method should not be called. Using any_instance is generally discouraged, so I would be...
Matilda Smeds
1

votes
1

answer
78

Views

Rspec testing Sentry's Raven capture_exception

Let's say I have this snippet of code... Raven.capture_exception(error, { extra: { error_message: message } }) end I have tried to use expect(Raven).to receive(:capture_exception).with(...) and no matter how I slice this, I can not seem to bind an expect to Raven so I can verify it was sent the logg...
Chris Hough
0

votes
0

answer
6

Views

Run rspec test suite multiple times with different parameters

I have a suite of specs to run. I would like to run the specs multiple times with different parameters each time. For example, I am testing the SQL scripts against two different database versions. The test cases are the same, but the connection string is different. How will I achieve this? I am new...
Krish
1

votes
1

answer
48

Views

Rspec testing of Rails gem

At my job we have a number of rails projects with similar functionality. We have refactored some of the common functionality out into a gem that is included in all the projects. The gem is just another rails project, providing models, controllers, and views to be added to the projects that include...
Fred Willmore
1

votes
1

answer
256

Views

Rails 4: PG::InFailedSqlTransaction when testing a rake task with RSpec

I am currently trying to test a rake task with RSpec. My Rails version is 4.2.4 and rspec-rails version is 3.3.2. I've have the following in rails_helper.rb: ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' require...
DaniG2k
1

votes
0

answer
59

Views

Using RSpec to loop through multiple spec groups

I'm somewhat new to this so bear with. I'm trying to execute several groups of tests independently via RSpec::Core # Example spec_groups = [['spec', 'spec2'], ['spec3', 'spec4']] spec_groups.each do |spec_group| RSpec::Core::Runner.run([spec_group]) RSpec.clear_examples end Two groups of specs - I w...
user3761590
1

votes
2

answer
400

Views

Rails 5 rspec test failing for uploaded file stub

In my rspec for uploaded files I am stubbing a function like this: allow(ABCCLass::XYZProcessor).to receive(:prepare_processing).with(csv_statements).and_return(nil) and let(:csv_statements) do [fixture_file_upload('transaction.csv', 'application/csv')] end I get error in expect: expected Rack::Tes...
Shehbaz
1

votes
1

answer
124

Views

Factory for database view in factory_girl

I am using Rails 5.0.2 with factory_girl_rails and RSpec. I have 3 associative models like this: /app/models/ticket.rb class Ticket < ActiveRecord::Base has_many :ticket_snapshots, foreign_key: 'duckduck_ticket_id' end /app/models/ticket_snapshot.rb class TicketSnapshot < ActiveRecord::Base belongs_...
Bijan Hoomand
1

votes
1

answer
30

Views

Ensure label belongs to its checkbox

I have a checkbox and a label for it. Now I want to ensure that the checkbox belongs to its label, like checkbox1 -> label1. How to do it on capybara?
gilbertlcsndle
1

votes
0

answer
181

Views

RSpec Stubbing Java Static Method ArgumentError

I am attempting to stub a Java static method in my specs for my JRuby class which imports some Java libraries. I get the following error for the method call: Failure/Error: JCoDestinationManager.getDestination('properties') ArgumentError: Wron...
mltd
1

votes
0

answer
54

Views

Rails 4.2 - Failing to stub delayed response for image with puffing billy - image not cached and new http connections are disabled

I have rspec tests and I feel there is a bug with puffing billy or maybe I am misunderstanding the use of whitelists in the settings. Basically the test is about checking that, if a third party hosted image (on a service called Cloudinary) takes time to be downloaded by a page, then the user sees a...
Mathieu
1

votes
1

answer
343

Views

Rspec and commit callback giving an incorrect result

I have a User and Role model: class User < ApplicationRecord has_and_belongs_to_many :roles validates :roles, presence: true, on: :save after_create_commit :assign_role private def assign_role self.roles { where(name: :client) } end I can't get the following Rspec to pass: describe '#assign_role' d...
chell
1

votes
0

answer
55

Views

Rspec response changes inbetween calls

I'm using the below line of code to check that a controller renders a response with parameters expect(controller).to receive(:render).with('orders/order_pickup/layout', {:locals=>{:state=>'pickup'}}) But when I run the rspec test, I get... Diff: @@ -1,2 +1,2 @@ -['orders/order_pickup/layout', {:loca...
Patrick Stetz
1

votes
1

answer
512

Views

Devise & Factorybot authentication for RSpec POST request

Setup using devise_token_auth, Factorygirl, and RSpec. Trying to sign in a user, and make a post request, but I am getting 401 unauthorized response. /spec/controllers/scripts_controller_spec.rb module Api::V1 RSpec.describe ScriptsController, type: :controller do let(:user) { FactoryBot.create(:use...
AakLak
1

votes
2

answer
402

Views

Rspec's expect change count not working

Here I'm testing the changes in current_user.messages.count after the current user sends a valid message. Here's my code: spec scenario 'adds to their messages', js: true do expect { find('#message_content').send_keys(:enter) }.to \ change(current_user.messages, :count).by(1) end test.log # ... Conv...
gilbertlcsndle
1

votes
0

answer
58

Views

Capybara Rspec routing incorrectly

I'm working on feature tests for my rails app and completely confused. I've created a test to log in which is routing me back to my root path of /. 1) Sign in user can sign in with valid credentials Failure/Error: expect(page).to have_content I18n.t 'devise.sessions.signed_in' expected to find text...
Godzilla74
1

votes
0

answer
78

Views

rspec returns nil instead of default database value

I have a spec that posts to an endpoint and then checks to see if the default value has been assigned, but it fails (expected: 'uncategorized' got: nil): it 'defaults to uncategorized when none is given' do post wikis_path(params: { wiki: { content: 'Some content' }}) expect(Wiki.last.category).to e...
oneWorkingHeadphone
1

votes
2

answer
128

Views

RSpec expectation on stub fails

Here's the call I would like to test expectations for: UserMailer.invoice_paid(user, invoice).deliver_later Rails 5 ActionMailer behaviour in :test mode seems to return nil on every method of an ApplicationMailer class. This should be fine since I can just stub it like so: invoice_paid_dbl = double(...
Archonic
1

votes
1

answer
70

Views

Checking on empty gems cache fails using Serverspec for Docker image build testing

I'm currently having an issue with testing Docker image builds by means of Serverspec. In a nutshell, what I want to do is ensuring that during the image build the Ruby gems build cache gets cleared explicitly, e.g. by issuing rm -rf /usr/lib/ruby/gems/*/cache/*.gem in the Dockerfile. The Dockerfil...
pklndnst
1

votes
1

answer
121

Views

Cocoon callbacks aren't fired when called from rspec

I have a page with nested fields that works well in development environment. I use an after-insert callback to number the field labels. So this creates the 'pericoop 1, pericoop 2' labels. However, when I test the page from rspec, the labels aren't numbered. When I save_and_open_page, I see just the...
andreheijstek
1

votes
1

answer
161

Views

Rspec: Save record after previous tests

I want to run tests dynamically, using the loop. What I have: let!(:product) { create(:product) } let!(:data) { product.some_data_object } let(:run_action) { patch :next_status, params: { id: data.id } } STATUSES.each_with_index do |status, index| it 'changes status from #{status} to #{STATUSES[inde...
taras
1

votes
0

answer
76

Views

How to print an exception under rspec execution log and rails console?

When Letter Opener email is triggered, it get printed into test.log. I need it to print it under console log. When Feature spec is running and if exception is occurred, it should get printed into server log on terminal. How to inspect the exception when email is triggered in letter_opener_email conf...
Rhunal
1

votes
1

answer
273

Views

rspec issue while testing two classes with the same name under different namespaces (modules)

Disclaimers: I'm pretty new to ruby Please don't ask me why I'm using the same class name in two different modules. I'm only trying to understand why rspec behaves this way; I found it confusing and could not find answers online. Description of issue: I have two .rb files in /lib. Both have a class...
Deba_san
1

votes
0

answer
10

Views

DRY-up `change` matcher expectations

Is there any better way to DRY below expectation? expect{ create(:counter) }.to change(Counter.count).by 1 expect{ create(:counter) }.to change(User.count).by 1 Below worked: [Counter, User].each do |model| expect{ create(:counter) }.to change(model.count).by 1 end Looking for the syntax like below(...
Rhunal
1

votes
1

answer
36

Views

Rails custom model validator fails rspec tests

I have a custom validator to verify the content of 2 fields in my database. When I use it through my UI, it works fine, however my rspec tests are failing and I can't understand why. Here is the rspec test: require 'rails_helper' RSpec.describe Device, type: :model do before(:each) { @user = User.c...
Godzilla74
1

votes
0

answer
20

Views

Rspec tests to voluntarily drop db connection

We have a RoR 5 app which has threads created in its rails runner script. I need to test on how system behaves if the app drops off db connections(ActiveRecord, MYSQL database). This occurred in production and the app went to 'unable to connect to mysql error' state . Manually, I can just reboot the...
user2452057
1

votes
1

answer
285

Views

How to click on the second element in capybara with css

I have a set of following code inside table: I am using capybara and I want to click on the second element. I tried using: page.all(:xpath, '//i[@class='fa fa-pen']')[1].trigger('click') -->resulted in clicking all elements and page.all(:xpath, '//i[@class='fa fa-pen']')[1].click -->resulted in Cl...
A J
1

votes
0

answer
109

Views

ActiveJob Rspec Test failing

I have the following Rspec test for an ActiveJob: require 'rails_helper' RSpec.describe ProofreadDocumentReportJob, type: :job do before do ActiveJob::Base.queue_adapter = :test end subject(:job) { described_class.perform_later(create(:report)) } it 'queues the job' do expect { job } .to have_enque...
chell
1

votes
1

answer
236

Views

How to test ActiveAdmin?

I'm using ActiveAdmin on my rails project, and I would like to know how test it, like how does activeadmin usually test? Since there's no tutorial on the internet, is it necessary to test it?, like this answer I found https://softwareengineering.stackexchange.com/questions/256557/should-i-be-writing...
gilbertlcsndle
1

votes
0

answer
74

Views

RSpec: application layout rendering blank

I am working in a mountable engine, which might have something to do with this problem. I have a page on which I am trying to test for the presence of some content. Right now, I have hardcoded an inline template. pagescontroller#show: def show respond_to do |format| format.html { render inline: 'Du...
Feliks Montez
1

votes
1

answer
75

Views

How to check session params in rspec?

When user visit some page on the site, his session marked with some values. How I can check it with Rspec? I can't find any information about it. Update: Rails 4.2.8
alexeysh
1

votes
2

answer
177

Views

RSpec check title

help me please. I need to test view title with rspec, capybara. I have spec: require 'rails_helper' RSpec.describe 'static_pages/home' do it 'display correct title' do render expect(response).to have_title('Home page') end end home.html.erb: djeje Home pagexbdkek Hello RSpec is passed without failur...
Postanova
1

votes
0

answer
59

Views

rspec/mocha error when testing facter fact

I've written a very simple facter fact. It looks like this: # Kubadmin facts # require 'json' Facter.add(:has_kubectl) do confine :kernel => :linux setcode do Facter::Core::Execution.which('kubectl') end end Facter.add(:kubernetes_version) do confine :kernel => :linux kubernetes_json = Facter::Core:...
jaxxstorm
1

votes
1

answer
136

Views

Ruby on rails: Rspec routing error when testing for a successful http status

So I am having trouble passing these specs in a ruby on rails application: require 'rails/all' RSpec.describe WikisController, type: :controller do let(:user) { User.create!(email: '[email protected]', password: 'password') } let(:wiki) { Wiki.create!(title: 'New Wiki Title', body: 'New Wiki Body',...
Claire Meadows
1

votes
1

answer
75

Views

Error running rspec in window: Webpack binstubs not found

When I run rspec I get the following error: 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/l...
Chloe
1

votes
0

answer
93

Views

Undefined method index? pundit testing in Rails

I am using Pundit for authorization in my application with rspec for testing. require 'rails_helper' describe SubjectPolicy do subject { described_class.new(user, subject) } let(:subject) { Subject.create } context 'is an administrator' do let(:role) { Role.create(role_name: 'admin') } let(:user) {...
Trenton Tyler

View additional questions