Questions tagged [rspec]

RSpec is a behavior-driven development (BDD) framework for the Ruby programming language, inspired by JBehave. It contains its own fully integrated mocking framework based upon JMock. The framework can be considered a domain-specific language (DSL) and resembles a natural language specification.

Filter by
Sorted by
Tagged with
0 votes
1 answer
22 views

How to test redirect_back in RSpec 3.12 requests?

My application manages treatments as a list of tasks. Tasks are created and edited through a modal window invoked from the treatment Show view. When closing the task form, I redirect_back to the ...
user1185081's user avatar
  • 1,974
0 votes
0 answers
15 views

How can I send files to test a request endpoint with Rails and RSpec?

I've been spending my evening trying to figure this out, to no avail. I am running on Rails 7. ​ I am writing requests tests in Rspec to test an endpoint, that attaches pictures to a user. ​ Sending ...
m3.b's user avatar
  • 527
-1 votes
0 answers
59 views

How to run Rspec on remote server through capistrano before or after deployment

How to run Rspec on remote server through Capistrano after deployment, if its failed revert to previous version. I am using Capistrano 3 and rails 7 I tried below code but it runs test cases on local ...
Akeel Ahmed Qureshi's user avatar
1 vote
1 answer
41 views

RSpec system test can't visit newly created record from a factory

I'm trying to login a user and visit a page for a record that this user owns. RSpec.describe 'User matters', type: :system do context 'urgent matter flow' do let!(:matter) { create(:matter, :...
Frexuz's user avatar
  • 4,774
0 votes
0 answers
23 views

Capybara::ElementNotFound - navbar item in toggled navbar

I am testing elements in my navbar, and it currently fails to recognise an item. I first checked with save_and_open_page, and the page really looked correct, so I could not understand why my test ...
andreheijstek's user avatar
0 votes
0 answers
17 views

Implementation of Parallel test execution by customizing an existing Ruby-Rspec framework

We are working on an existing Ruby-Rspec framework which designed to execute sequential tests on different batches which is statically designed in framework itself. Now, we are trying to enhance it by ...
Karthik's user avatar
0 votes
2 answers
54 views

Ruby Rspec, Finding how many times a worker being called recursively

I need to test a worker on Rspec, to Find how many times the same worker being called again and again in recursive manner. Eg: Class Myworker def perform(id) model = Mymodel.find(id) ...
jansha's user avatar
  • 162
0 votes
1 answer
50 views

How do I spy on objects within the context of a rake task with rspec?

I have the following setup: class Simple def self.test; end end task a_simple_job: :environment do counter = 0 while counter < 2 Simple.test counter += 1 end end require "...
ohhh's user avatar
  • 697
0 votes
0 answers
94 views

Giltab CI and images platform

I have a Rails app and the whole CI on Gitlab. I've built for the for time a GitlabCI image (stored on Gitlab Registry) and I'm facing an issue with Spring. When I use the image built from a Macbook ...
brcebn's user avatar
  • 1,603
0 votes
1 answer
46 views

undefined method sign_in for rspec

I'm writing a simple controller test to ensure that we get a 200 status upon a GET request. Every answer I've encountered online says to make sure we are including the correct Devise helper in ...
Misha Krul's user avatar
1 vote
1 answer
68 views

How to ask for a specific format in Rspec request?

The get_children method of my Playgrounds controller renders a specific javascript template, or json formated data: # GET children from playground def get_children @business_areas = @playground....
user1185081's user avatar
  • 1,974
0 votes
0 answers
22 views

How to check a record de-activation with RSpec 3.12?

My Playground controller does not really delete records, it flags them as inactive if one wants to remove a Playground: def destroy @playground.set_as_inactive(current_login) respond_to do |format|...
user1185081's user avatar
  • 1,974
0 votes
2 answers
36 views

How to concatenate attributes in RSpec 3.12 requests?

Edit views in my application provide expected data fields, and also extra fields that do not belong to the model, such as annotations and translations, which are processed by the controller method ...
user1185081's user avatar
  • 1,974
1 vote
1 answer
30 views

In Rails testing / rspec what is the difference between `request: true` and `type: request`?

I've been looking over tests and I've seen request: true and type: request used, seemingly interchangeably. I was wondering what the difference between them are and if there is any, and which the ...
CafeHey's user avatar
  • 5,801
1 vote
1 answer
31 views

With Rails and Rspec, is there a way to see what page an action really takes you to?

I have a rails test in which I go to a page and enter information, save the page (which takes me back one page), and attempt to come back to see if the data is still there. I am hitting a wall, but ...
wruckie's user avatar
  • 1,739
1 vote
1 answer
38 views

How to re-use FactorBot factories to build request attributes when testing with RSPEC?

I am refactoring an application based on Rails 5.2.4, with rspec 3.12. I focus on requests tests which do not exist yet. While defining requests tests for the Playgrounds controller, I wish to re-use ...
user1185081's user avatar
  • 1,974
0 votes
1 answer
37 views

How to configure Rails to use subfolders in models with RSpec?

I have subfolders inside the models folder: app/models/foos/bar.rb Autoload paths is configured in application.rb: module AppName class Application < Rails::Application config.load_defaults 7....
B Seven's user avatar
  • 44.9k
0 votes
0 answers
49 views

TimeCop not adjusting time in model method

Using Rails, Rspec, FactoryBot, Capybara, Whenever, TimeCop. I'm trying to trigger a modal method at '00:01, every 1.day' (12:01am daily) during an Rspec/Capybara test, in order to test the code that ...
daveasdf_2's user avatar
0 votes
0 answers
48 views

Rspec: block runs multiple times

I have a simple test in rspec as follows: RSpec.describe "api_request", type: :request do context "when a certain case is true" do it "returns true" do ...
mrateb's user avatar
  • 2,395
0 votes
0 answers
11 views

Is there any way to generate a unique HTML report with parallel_rspec for multiple threads? Not 'n' reports, but only one including all the results

Well, so... the last question in this regard was answered 8 years ago (this one), and I haven't found any newer questions after that. This solution is great, but creates multiple html files, so it ...
Manu Donoso's user avatar
0 votes
2 answers
78 views

Ruby, factorybot error duplication with rspec

Ii stuck on an error with my app. I'm testing it with RSpec and in my PagesController test, at the start: let(:user) { create(:user, favorite_category: "Elettronica") } I get error : ...
antonio 's user avatar
0 votes
0 answers
18 views

unable to set Thread for current user while running controller rspec

We have written after_create callback where we use Thread.current[:current_user_id] but While running controller rspec spec fail because of Thread.current[:current_user_id] got as nil.
Uday Magdum's user avatar
0 votes
0 answers
69 views

How to write rspec test for a helper method inside a class in Ruby Rails?

module MyApp class V5::Org::LeaveRequests < Base helper do def leave_requests_for_member! error!(...) unless condition end I try with my code: describe_api V5::Org::...
Alex's user avatar
  • 102
1 vote
1 answer
28 views

RSpec how is be_invalid matcher made available

I noticed following line expect(actual).to be_invalid while I was looking at https://github.com/perfectline/validates_url/blob/81ec1516423af0b4fdc7cabbcda0089e434f2703/lib/validate_url/rspec_matcher....
Jignesh Gohel's user avatar
0 votes
1 answer
32 views

Writing simple RSpec model test

i am trying to write a simple User model test for RSpec. I have installed all necessary gems related to this but when I try to run this simple test code # spec/models/user_spec.rb RSpec.describe User, ...
morris menanya's user avatar
0 votes
0 answers
63 views

Capybara sends unexpected google http requests

In my Rails 7 app I've got a simple single page web form where user has an input text field and submit button. After user provide some text inside of the field and push the submit button, the form ...
mr_muscle's user avatar
  • 2,644
0 votes
1 answer
40 views

Tests: How to check if a sidekiq job enqueued another sidekiq job

I have this two example class, and I want to write a rspec that runs PaymentCheckJob for first time, and if payment_type == 'ticket', I want to check if it enqueued another sidekiq job class ...
Felipe Junges's user avatar
0 votes
1 answer
49 views

Rails tests are passing but server refuses to start on production due to syntax error [closed]

This is one weird issue I am facing. All the test cases are passing on the CI/CD but there's a syntax error in one of the files. And when this changes goes to production the server refuses to start. ...
aks's user avatar
  • 8,993
0 votes
1 answer
21 views

Rspec contexts running together when separate due to name

I have some tests like this context 'Main block' do let(:variable) { 'test' } pseudo and tests end context 'Main block two' do let(:variable2) { 'test2' } pseudo and tests end ...
James B's user avatar
  • 432
0 votes
1 answer
10 views

accepts_nested_attributes_for works in app but not with specs

My shop model with accepts_nested_attributes_for class Shop < ApplicationRecord has_many :open_slots, dependent: :delete_all validates :name, presence: true belongs_to :user ...
Anna Bozio's user avatar
1 vote
0 answers
30 views

No route matches [GET] error in feature spec for update button routed to PUT

I'm writing a feature test for a Rails 7 application. I'm using RSpec, Capybara, and Capybara-Webkit. The feature I'm testing archives a record(a developer app) when the user clicks an 'Archive' ...
abron's user avatar
  • 25
2 votes
0 answers
146 views

Handling args and kwargs Ruby 3.0 and 3.1 with Rspec

I am doing an upgrade from Ruby 3.0.6 to Ruby 3.2.2 on our project, and I ahve encountered a weird issue that I tried to understand for past few days. We are using RSpec for tests and in one of the ...
Nedim Ramic's user avatar
0 votes
1 answer
32 views

How to catch ActiveRecord::NotNullViolation in Rspec?

I have the following Rspec: before { model.update(calendar_id: nil) } ... expect { job.perform_now(item_id) }.to raise_error(ActiveRecord::NotNullViolation) which fails with the following error ...
53c's user avatar
  • 401
0 votes
0 answers
43 views

RoR, How can I unit test controllers using RSPEC which are protected by JWT authentication system?

I'm trying to unit test RoR api controllers using rspec-rails gem. All my controllers are implemented this ProtectedController class which intercept all request and validate the authorization header ...
Safouane Jelassi's user avatar
0 votes
0 answers
49 views

Testing a db migration in rails 7

I've been trying to write a spec to test a rails migration, but any guides i find online, (e.g. https://nebulab.com/blog/testing-ruby-on-rails-migrations) use the deprecated: ActiveRecord::Migrator....
kujosHeist's user avatar
0 votes
2 answers
43 views

Rspec stubbing a constant set to a Rails credential

I have a class: class Vendor::Connection VENDOR_CLIENT_ID = Rails.application.credentials.vendor_api[:client_id].freeze VENDOR_CLIENT_SECRET = Rails.application.credentials.vendor_api[:...
Paul Pettengill's user avatar
0 votes
1 answer
48 views

Is it possible to combine RSpec shared examples with "it" blocks, and therefore not triggering the context to run twice

I've got a bunch of integration tests that have one part that can be shared across most tests, and a specific part that is specific to any one test. These integration tests run against an external ...
J. Strange's user avatar
0 votes
1 answer
17 views

RSpec Request spec setup issue

I have the following spec: it "allows a valid request" do user = create :user headers = {"Authorization" => "Bearer #{user.api_token}"} get "/api/v1/user&...
Neil Middleton's user avatar
0 votes
1 answer
40 views

How to select an invisible radio button

I have the following erb <%= form_with model: @car, remote: true do |form| %> <%= form.radio_button :color, "red", style: "visibility: hidden" %> <% end %> I ...
Sig's user avatar
  • 5,626
1 vote
2 answers
80 views

Matching of randomly ordered array when test nested hash with RSpec

In my RSpec tests I often have the challenge to compare deep nested hashes like this { foo: ["test", { bar: [1,2,3] }] } The values [1,2,3] are read from a DB where the order is not ...
23tux's user avatar
  • 14.2k
3 votes
0 answers
311 views

`FrozenError: can't modify frozen Array` in Rails 7 Engine when running `rspec`

I just upgraded an Engine from Rails 5 to Rails 7. This error started appearing at Rails 6.1.7.6, but I thought perhaps it might've been fixed in Rails 7. Here's the error I get when I run rspec An ...
John's user avatar
  • 9,314
2 votes
1 answer
45 views

How can I run an rspec expect statement in a ruby debugger?

Whenver I want to write a semi-complex expectation, I start having to play around with matchers, seeing how can I combine them. For example, if I want to test that all hashes of an array of hashes don'...
Damian Pereira's user avatar
1 vote
1 answer
40 views

How to make rspec expect-receive to only care about some method call

I have a Rails model that has two after_save callbacks, each one calls a method on QueuePublisher class with different arguments. I want to test the callbacks separately, so that one test tests that ...
Mika's user avatar
  • 1,429
0 votes
1 answer
28 views

Rails controller tests: "Filter chain halted" never appears

In development, my Rails log shows Filter chain halted when some before_action filter is unsatisfied, but when I run controller tests in rspec, I don't get any such information in the log. Setting up ...
JellicleCat's user avatar
  • 28.9k
0 votes
0 answers
23 views

Params missing on Rails testing with Rspec and Capybara

I'm working on a Rails application and implementing the testing phase using Rspec and capybara. Here's the scenario: scenario 'A valid user uploads a valid note' do tag topic faculty ...
Damiano's user avatar
1 vote
1 answer
47 views

NoMethodError: undefined method `[]' for nil:NilClass when creating a new session and passing session parameters

As i received advice from stack overflow, I was conducting functional tests in integration test file however when i am creating a user sign in test session , I am getting the following error: Finished ...
Fardeen's user avatar
  • 21
0 votes
0 answers
54 views

How to avoid using allow_any_instance_of on module instance method rspec

I know using allow_any_instance is discouraged in Rspec, since it can lead to mixed/strange behaviours with all instances returning something we might not want So for class I would do let(:client) { ...
aldm's user avatar
  • 363
-1 votes
1 answer
57 views

How to test browser automation code with rspec

I'm working on a project that requires a lot of browser automation to retrieve data, populate forms, etc. I've used capybara and selenium in the past to do automated testing of websites, but I've ...
jerhinesmith's user avatar
  • 15.3k
0 votes
1 answer
40 views

How do I perform these actions with Capybara?

If possible, please let me know the different variations of how to do these two things, I would much appreciate it. I have tried FOR DAYS to do these things. edit - it is an hobby 2017 rails project i'...
daveasdf's user avatar
  • 125
1 vote
1 answer
190 views

Selenium::WebDriver::Error::WebDriverError: no sessionId in returned payload

Tests suite with Rspec and Capybara was successful until now, but I suddendly got that error message without writing any new spec : ` Failure/Error: visit root_path Webdrivers::VersionError: ...
Sibylle Courcel's user avatar

1
2 3 4 5
365