All Questions
Tagged with rspec ruby-on-rails-3
1,414 questions
0
votes
0
answers
67
views
Rails rspec feature itegration testing for basic auhentication
class MenucardController < ApplicationController
http_basic_authenticate_with name: 'admin', password: 'password'
def index
@menu_items = CsvFileTest.find_each(batch_size: 10)
end
end
...
1
vote
0
answers
149
views
Test recaptcha with rspec
I'm using recaptcha gem and I need to cover the alternative scenario on test spec (when captcha is not valid)
This is the code that the gem suggests in the controller
def check_captcha
return if ...
0
votes
1
answer
899
views
Write a RSpec test for method that takes a single argument
I need to write the RSpec test case for a module that has a private method and takes a single Argument.
module x
private
def fun(para)
end
end
I have a spec file where I tried to write a case ...
0
votes
1
answer
252
views
Rspec test fails while rendering
For my user controller, while running the test cases I am facing render issue. It is redirecting to http://test.host/sign_in instead of rendering new.
Controller code
def create
@...
0
votes
1
answer
67
views
Finding a weird symbol in Capybara
I'm currently trying to find a symbol on a page. I have the HTML tag and the find method that I'm using. However it's not able to find this symbol. I'm not sure what I'm doing wrong to do so.
<div ...
2
votes
1
answer
6k
views
how to check if a method is called or not in rspec
as i try to check internally my method was calling or not in rspec but it got the following errors
context "#Meeting_schedule" do
let(:meeting_schedule) { FactoryGirl.create(:...
0
votes
0
answers
155
views
Rspec reloads removes the value that updated earlier
why reload removes the values that has been updated on before(:each)
is there any other approach for doing such things
thanks in advance
i have written my rspec as below
let!(:book){FactoryGirl.create(...
0
votes
1
answer
2k
views
While running the rspec it shows does not implement( allow_any_instance_of )
My rspec line
allow_any_instance_of(School).to receive(:admission).and_return(:body)
I have my admission method in my lib/school.rb
module School
def self.admission()
like this, but when i run the ...
0
votes
1
answer
985
views
I can't execute rspec using 'bundle exec rspec'
I'm very new to coding and I have been learning ruby through the app academy open bootcamp. I have gotten to the Rspec topic, but after installing the gems from the gem file provided in the course:
...
1
vote
0
answers
182
views
Byebug does not pauses in controller in RSpec request spec
I have added byebug breakpoint in spec code and it pauses the code there.
require 'rails_helper'
RSpec.describe "UsedCars", :type => :request do
describe "POST /used_cars" do
...
1
vote
2
answers
312
views
RSpec: Can we configure an expectation to return two different value? I want to test retry mechanism
So I have a retry rule in my application. I wanted to test that using rspec.
When I call service without passing account ID it should give me false and when account ID is passed it should give me true....
0
votes
1
answer
289
views
expected ActiveRecord::RecordNotFound but nothing was raised
How to get the test pass for this error?
Rspec result
**2) Api::V1::UsersController GET #show - a user it fails showing a user
Failure/Error:
expect do
get 'show', params: { id: 2 }
end.to ...
0
votes
2
answers
1k
views
Capybara / RSpec Ensure somethinng does not exist anywhere on the page
I want to find out how to ensure something does not exist on the page, specifically, a div with a known value. Essentially, I'm removing an element and I want to test that the element with 3 classes ...
2
votes
1
answer
358
views
Rails: switch to puma for request specs
We are working on a rails 3.2 app with RSpec 3.7 and want to use puma as web server for our rails request specs.
We know we can switch the server for Capybara feature specs using
Capybara....
0
votes
2
answers
1k
views
How to check if the inside method has been called using RSpec
I got a method to update the person by id:
def update_person(id)
handle_exceptions do
person = Person.find(id)
#...other
end
end
When this id doesn't exist, the handle_exception should ...
0
votes
2
answers
778
views
RSpec - How to test the if-else block in update method of controller
Let's say I have a database to store the data of people (name, email). And there's an update method in the controller. The method is like:
def update
@people = People.find(params[:id])
if @...
4
votes
2
answers
5k
views
Rspec - Compare two json values
I got a response from render json: { success: 'Success' }, I met a problem when I want to test if the response received the content like this. My unit test is:
let(:success) do
{
...
-2
votes
1
answer
2k
views
Ruby Rspec should_not_receive not working
For this below code snippet:
@by_hidden.should_not_receive(:by_limit).with(100).and_return(@by_limit)
I am facing error as
@by_hidden.should_not_receive(:by_limit).with(100).and_return(@by_limit)
...
0
votes
1
answer
100
views
How to filter out one method call from many others with `expect().to receive()` in RSpec
I have such a code:
class ClassB
def print_letter(arg)
end
end
class ClassA
def self.my_method
ClassB.print_letter("a")
ClassB.print_letter("b")
end
end
RSpec.describe ClassA do
...
-1
votes
1
answer
451
views
How to write RSpec test for the following code
I have the functionality of my code working correctly, but need to create an RSpec test that covers it.
My routes.rb:
resources :movies do
#member routes for individual ones
get '...
1
vote
1
answer
3k
views
Rspec;How to include params inside the body
Rspec spec fails on the following test case. Can anyone please help me with sending params inside the body?
Test case:
describe 'POST search' do
it 'renders search' do
request.headers['...
0
votes
0
answers
60
views
Currently on Rails 3, starting to write unit tests, so is it better to go with Rspec or Minitest given the future of Rails 6 and unit testing?
I need advice. Our software is currently on Rails 3 and we're starting to write unit tests, but we can't decide whether to go with RSpec or Minitest. we're considering to go with RSpec purely over the ...
1
vote
1
answer
794
views
Rspec 3.8 before block not deleting record
In app/models/car.rb the class method stock looks in part like this:
def self.stock
raise Exception, "Property amount not set" if Property.get(:amount).nil?
...
end
This Property is ...
9
votes
1
answer
15k
views
Rspec request spec examine response body
Since rspec 3.5 request specs are used to test controller behaviour plus route testing and the correct rendering of the view with the content.
The last part troubles me a bit since i do not understand ...
0
votes
0
answers
39
views
Rspec Test CanCan AbilityClass not building rules in Rails3.2
In my Test environment Cancan does not build its rules.
ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.is_admin?
can :manage, :...
0
votes
1
answer
319
views
Rspec: Test an exception which is not handled
In my public method #recalculate, calling the private method1. This method throw exception 'StandardError'. I want to test this scenario, however getting an error.
Note: I don't want to handle an ...
1
vote
1
answer
2k
views
Rspec: How to test an exception is raised in private method?
Getting error while testing an exception in a private method. How to test an exception is raised in private method which is called from a public method?
Public
def public_method
private_method
...
1
vote
1
answer
699
views
Rspec: Getting error while testing private method
Getting error while testing a private method. Please suggest how to test private method is called from a public method.
Public
def public_method
private_method
end
Private
def private_method
...
1
vote
1
answer
392
views
Ruby: How to test private method?
I have implemented Optimistic Locking for Race Condition. If lock_version doesn't match with the updated lock_version in the database, then it will trigger retry three times. Can you suggest how to ...
2
votes
1
answer
5k
views
Rspec: How to test retry?
I have implemented Optimistic Locking for Race Condition. If lock_version doesn't match with the updated lock_version in the database, then it will trigger retry three times. Can you suggest how to ...
0
votes
1
answer
1k
views
Rspec: How to test an exception which is getting raised in private method?
In my public method #recalculate, calling the private method1. This method throw exception 'ActiveRecord::StaleObjectError'.
def recalculate
method_1
self.save!
end
private
def method_1
...
1
vote
1
answer
878
views
RSpec: How to write unit test case to receive an exception which is getting raised in private method
I have implemented Optimistic Locking for Race Condition. For that, I added an extra column lock_version in the Product. Method: recalculate is calling private method_1 then it saves (save!) the ...
0
votes
1
answer
2k
views
Rspec for Faraday::ConnectionFailed
I have following method in the code for which I need to write the spec (for rescue block). I tried few things but not getting success so that my spec will enter in the rescue block. I read about using ...
2
votes
1
answer
711
views
RSpec: How to run the feature specs after all other specs
We have a rather complex integration spec setup with capybara and chrome. This leads to slow feature specs.
It would be nice if the feature specs would be executed after all other specs. Because it ...
2
votes
1
answer
1k
views
Rails Stub a variable inside module
I wrote a unit test for this module and want to stub current_account variable which comes from application controller.
(its global method written in application controller)
Module Foo
def ...
0
votes
1
answer
1k
views
Rspec testing fail strong params
Trying to get this one to pass for a while, not that familiar with Rspec, tried couple answers, and no luck yet, I have these two parameters being required on my controller as follow:
class ...
1
vote
1
answer
2k
views
Rspec Testing : NoMethodError - undefined method 'id' for nil.Nilclass
When I am running rspec testing for a controller in Rails, I get the error "NoMethodError : undefined method 'id' for nil.Nilclass" at the second line.
params[:tag_id] is passed down from the front ...
0
votes
1
answer
134
views
Rspec return No route matches when using scoped route
I have a route that is defined as this in my routes.rb as so
scope ':prefix', as: :foo, controller: 'foo_paths', action: :placeholder do
get 'foo/:id', as: 'result'
end
The issue is when running ...
0
votes
2
answers
1k
views
Capybara test case for Login page authentication
I have capybara test case below.
it "Testing login page with valid data" do
fill_in 'email', with: '[email protected]'
expect(page).to have_selector("input[value='[email protected]']")#Checking ...
1
vote
1
answer
750
views
Custom validator on associated model make other Rspec model tests break
I have 2 models sharing a simple belong_to/has_many relation: Room belongs to Building
I created a custom validator called total_number_rooms_limited_to_15 that ensures I can't create more than 15 ...
0
votes
1
answer
54
views
after upgrading RSpec to version 3 I can't run single spec file anymore
We are in the process of upgrading rails from 3.4 to 4.2. When we upgraded the rspec to the latest version, even after forcing the rspec to run only one spec it runs around 900 tests but my file only ...
0
votes
0
answers
50
views
Rspec for controller
def finding
if params[:called_by] == ‘ATTACHMENT’
Dir.mkdir('tmp/tmp_pdf') unless File.exists?('tmp/tmp_pdf')
name = params[:ticket_attachment].original_filename
end
end
Above is my ...
2
votes
0
answers
810
views
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' -- while trying to start the server
I end up with this error:
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- bundler/setup (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/...
1
vote
1
answer
2k
views
How to stub model method for rspec controller test
I'm trying to stub the model method which I'm using in my controller, but it never seems to be working. Can someone let me know the proper way to do it
User Controller
if current_user.user_token
...
0
votes
1
answer
164
views
bundle exec rspec spec/requests/static_pages_spec.rb and error
I am using Michael Hartl's ruby on rail tutorial.
When I try to execute the command:bundle exec rspec spec/requests/static_pages_spec.rb
I get the following errors:
mudit@Bat:~/rails_projects/...
1
vote
1
answer
329
views
R Spec Stack level too deep (System Stack Error)
I have three models offer_ticket, event and offer and have three their respective factories below are the models and factories are given i got error stack level too deep.
There is loop execute ...
0
votes
2
answers
88
views
I need help to write the rspec test in rails
I have a items_controller.rb
def get_serialized_copy_of_item
@item= Item.find_by_id(params[:id])
if @item.nil?
head :no_content
else
respond_to do |format|
...
6
votes
1
answer
2k
views
Rails render_to_string using wrong format
I am encountering a problem with render_to_string using Rails 3.2.18 in which the function is trying to render the wrong view format despite its :formats option being correctly set (so for example ...
1
vote
1
answer
175
views
Using CanCanCan in a view failing tests
Hi I have a project with an ability:
can :set_to_user, Post
I then have in one of my views:
<div class: "btn btn-primary #{disable_button(!(can_set_to_user))}>
in a helper I have:
def ...
1
vote
1
answer
420
views
Rspec not finding routes that exists
I'm trying to write a controller test and Rspec isn't finding routes that I know exist and work fine on a development server.
In my routes I have a catch-all route that should redeirect to a ...