Questions tagged [rspec]

0

votes
0

answer
3

Views

Webmock: Boxr::BoxrError: 200: File Uploaded get correct return value as error

I'm currently working on a Ruby application using Boxr gem. The gem is use to interact with Box API. I created a Proxy class to make calls to Box API using the Boxr gem. I'm testing uploading a file to box. I created a method upload_file_to_box which pushes a file to a folder on Box. The method is w...
Steven Aguilar
1

votes
2

answer
1.3k

Views

How do I test the rescue block of a method with rspec mocks 3.3

Help me make this test pass: Here is an example of some rspec code, class User attr_accessor :count def initialize @count = 0 end # sometimes raises def danger puts "IO can be dangerous..." rescue IOError => e @count += 1 end #always raises def danger! raise IOError.new rescue IOError => e @coun...
Ziggy
1

votes
1

answer
244

Views

How to run same spec with different before hook in rspec

I maintain a gem that gathers data from various APIs. For APIs that require an API key, I have implemented scrapers to fall back on when no API key is set. My current solution to testing both the scraper and the API code is to have two spec files that are virtually the same except for a before hook....
DormoTheNord
1

votes
1

answer
197

Views

ActionMailer preview_path is not the RSpec default

I have an app that's throwing the following error every time the environment is loaded. Action Mailer preview_path is not the RSpec default. Preview path is set to: spec I'm not even sure what the preview_path here is or where it might be configured. Is there a way to adjust this or disable it? Than...
user2490003
1

votes
1

answer
339

Views

RSpec class_spy on Rails Mailer

I am trying to test that a specific mailer class is used when a model is saved. In my model I have: class Foo < ActiveRecord::Base def send_email if some_condition FooMailer.welcome.deliver_now else FooBarMailer.welcome.deliver_now end end def In my tests for Foo class I have the following it 'uses...
cassidycodes
1

votes
1

answer
196

Views

Why Capypara + Rspect tests still pass even though I delete application.js file?

I have rails app and have some ajax call in application.js file. O have rspec, capybara, webkit, factorygirl and databasecleaner for testing. I wrote feature tests which all pass. Then accidentally delete application.js file and run the tests, they still pass. Please help me to find out why. Thanks...
tkhuynh
1

votes
1

answer
184

Views

How to access an object's instance variables while stubbing?

I'm writing some tests for a web application and one of the controllers calls resolve on a Scope object, which returns a slightly modified scope. In the test I would like to stub this method to return the original scope (passed as a parameter to Scope.initialize). The Scope object class Scope def in...
DanielGibbs
0

votes
0

answer
9

Views

JSON::ParserError: 765

Am trying to test my controller using Rspec. when i am trying to run rspec test cases for json JSON::ParserError: 765 occurs.here iam attaching my code.if there is any solution class TopicsController < ApplicationController before_action :set_topic, except: [:create, :new, :index] def index @topics...
0

votes
0

answer
2

Views

Shoulda matcher scoped uniqueness tests against unallowed nil value in scope

My shoulda matcher is expected to validate the uniqueness of season_storage_id, scoped to epoch. It should do that ignoring case, since I'm upcasing the input before validation. #app/models/season_storage.rb before_validation :sanitize_inputs ... validates :storage_id, uniqueness: { scope: :epoch...
TopperH
1

votes
1

answer
1.4k

Views

RSpec Controller Destroy Testing

I'm building a test application that lets user create/delete posts. I'm having a bug in my destroy action that I'm finding difficult to debug. Here's my test: describe '#destroy' do context 'existing post' do let (:post) { FactoryGirl.create(:post) } it 'removes post from table' do expect { delete :...
segue_segway
1

votes
1

answer
182

Views

How to test Devise user was created with proper password with RSpec

Is there a way to test that a Devise user was created with the correct password in RSpec? I have a feature spec for creating a user, and have tried testing that created_user.encrypted_password eq User.new(password: same_as_created_user).encrypted_password but the passwords generated do not match.
ThomYorkkke
0

votes
0

answer
6

Views

Is there a way to use a matcher like 'Verify' in rspec?

So far I'm using 'expect' in my test framework which will stop the execution when it meets a fail condition. I want something like, the execution should happen even if it meets the fail condition. I could see that there is a matcher called 'Verify' in rspec where I need to inherit 'Test::Unit::TestC...
esakiraja
1

votes
1

answer
246

Views

parallel_tests RSpec improve performance

I have a suite of tests for a controller that makes calls to an external sandbox api for testing, which makes the performance rather slow. I'd like to improve performance by allowing parallel_tests to not only run suites in parallel, but individual describes. For example: RSpec.describe FooControlle...
jtmarmon
1

votes
3

answer
374

Views

Capybara doesn't find my route in engine

I started a new Rails 5 applications for myself to see how I can modularise an application with engines and simple test purposes. I decided to use Rspec and Capybara for integration tests. I have a very basic feature rspec: okinsmen/components/okm_backend/spec/features/humen_spec.rb require 'rails_...
patdec
1

votes
1

answer
372

Views

How to share RSpec let variables between shared contexts?

I'm trying to DRY my RSpec request specs by using shared contexts. I'd like to share let variables between shared contexts so that they inherit and extend from one another. Rspec.shared_context 'JSON request' do let(:headers) do { 'Accept' => 'application/json' } end end Rspec.shared_context 'Authen...
Marc Greenstock
1

votes
1

answer
35

Views

Rspec before(:each) works but before(:all) does not

My ProductCategory spec:- require 'rails_helper' RSpec.describe ProductCategory, type: :model do before(:each) do @product_category = create(:product_category) end context "validations" do it "should have valid factory" do expect(@product_category).to be_valid end it "should have unique name" do...
Umesh Malhotra
1

votes
2

answer
71

Views

Rspec - expected ActiveRecord::RecordInvalid but nothing was raised?

I'm creating tests using rspec and trying to raise an error "ActiveRecord::RecordInvalid", but I keep getting "expected ActiveRecord::RecordInvalid but nothing was raised" I'm pretty new to rspec testing and this is actually my first time directly asking a question on stack overflow. Thus my questio...
1

votes
1

answer
2k

Views

Testing a build association using Rspec in Rails 3

I have the following line in my create action of my teachers controller. @rating = @teacher.ratings.build(params[:rating]) unless params[:rating][:rating].blank? I know my associations are correct because this line correctly creates a new rating alongside a new teacher unless the rating is left blan...
James
1

votes
1

answer
1.2k

Views

RSpec attribute hash

Can someone explain to me what is wrong here. Learning RSpec - I am receiving a failed test with message - expected: "Miller" got: nil. I thought that the second 'before block' would simply merge the middle_name with the original @valid_attributes. What is the correct way to do this. I know that I c...
basheps
1

votes
1

answer
740

Views

Capybara drag_to function throwing NotImplementedError

I have a Rails app that i'm trying to test the drag and drop functionality on, I'm using capybara and rspec along with jquery ui for the dragging, it works fine in the browser but I can't get a working test for it. The error I get is as follows: source_element.drag_to(dest_element) NotImplementedErr...
Mike H-R
1

votes
2

answer
1.7k

Views

Issue with Paperclip and Rspec: undefined method `has_attached_file'

I'm adding Rspec tests to a project that didn't have rspec before, or automated tests at all. It is running on a Windows 7 box. When I run rspec, it shows the error: undefined method `has_attached_file' The main issue is that I'm writing just a simple test for a model that is not using Paperclip at...
Marco
1

votes
2

answer
2.1k

Views

why is this failing 'undefined method `destroy' for nil:NilClass' rspec rails

The idea of this test is to handle the event a record is not found. There for a destroy action should not take place and yet it is. I've chopped and changed it around, nut essentially the test reads right, so there must be a problem in my code. RSpec.describe Admin::EntriesController, :type => :cont...
rico_mac
1

votes
1

answer
990

Views

Rspec and sinatra just not working for me but I want them to

I've never used Sinatra before and I've never manually configured Rspec before (always used pre-written script for rails) but I wanted to give it a go. But I'm having trouble, I managed to get RSpec to sort of work but I'm running into errors just getting it to recognise methods from Sinatra. I'm wo...
Thermatix
1

votes
1

answer
177

Views

How to add custom text to success rspec message

I'm generating some automatic specs and I would like to have a custom success message with the times that the expectation was success. For example, I would like a report like: Opportunity .rating_info where the real estate kind is Monoambiente and there aren't assigned values is 0 when there are mul...
6

votes
3

answer
122

Views

Errno::ENOENT: No such file or directory @ rb_file_s_mtime after feature tests

When running feature Rspecs, I receive the following error (full trace at the bottom of this message) Puma output Rack app error handling request { GET /rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSm5kbUZ5YVdGdWRITXZSM0IxTkRGRFRWQlFaVXRNYVUxaVpuQjZXVmw1UTNBMUx6RXhNR1V3T...
Benj
1

votes
2

answer
310

Views

How to test actions with queue workers?

I have an action create in UsersController which looks like this def create @user = User.new(params[:user]) if @user.save sign_in_as(@user) Resque.enqueue(MailWorker, @user.email) redirect_to root_url, notice: "Thanks" else render "new" end end Before I added reqsue to this action, I've been testing...
evfwcqcg
1

votes
1

answer
1.6k

Views

Rspec and Carrierwave. When changing config.storage to file for testing, I get an ArgumentError is not a recognized storage provider exception

I have two carrierwave uploaders in my application. ImageUploader is for uploading locally and ImageRemoteUploader for uploading to Amazon S3 storage using fog. ImageUploader has storage set to :file and ImageRemoteUploader has storage set to :fog. This setup works fine, but when I start to set up m...
cgat
1

votes
1

answer
61

Views

Rspec: Avoiding out of sync issues with message expectations

Message expectations allow you to check if the object under test is sending the right message, but not that the target object can actually respond to this call. On the other end of the spectrum, integration testing checks that everything actually work, that is, that the calls are made, understood an...
Nekosan
1

votes
2

answer
2.4k

Views

include file ruby selenium

I have multiple ruby test cases for selenium-webdriver and all the files are sharing the same functions. is there any way to create a global file and include the file to these test cases instead of typing them over and over again for example - I create a file setup.rb def setup @driver = Selenium::W...
tanya
1

votes
2

answer
1k

Views

render_views returning NoMethodError

I'm currently going through the Ruby on Rails Tutorial by Michael Hartl, and in Section 3.2.2 of the tutorial, he talks about using RSpec to test for the titles of the page. My tests (which I wrote myself, following his tutorial) kept failing the title tests (it can find the tag, but the title is al...
Benedict Lee
1

votes
1

answer
1.3k

Views

Why can't my Rspec integration tests find my modules?

I'd like to be able to call login_as_admin and login_as_customer at any point in any spec file. I have a directory full of integration specs: /spec/features/area_spec.rb /spec/features/assignment_spec.rb /spec/features/etc… Each of which starts with: require 'spec_helper' require 'rspec_macros' I...
steven_noble
1

votes
1

answer
2.2k

Views

Rails “update_attributes” skipping validation?

I have the following simplified model: class User attr_accessible :password validates :password, :presence => true validates_confirmation_of :password, :length => { :minimum => 4 } end That's pretty straight forward. I'm testing it with RSpec/FactoryGirl, and have the following tests: it "cannot cr...
Bryce
1

votes
2

answer
363

Views

How can I delete test data left behind by Rspec's before(:all) hook?

I found out that using before(:all) in my specs generates test data that is NOT rolled back after the specs are run. I didn't know that I needed to use an after(:all) hook to delete them. Now my test database is filled with those records and I would like to reset it. How can I get this done? There...
hlh
1

votes
1

answer
134

Views

RoR, Rspec test mysteriously failing

I'm writing integration tests for creating a user account. describe "with valid information" do before (:each) do fill_in 'first name', :with => 'test' fill_in 'last name', :with => 'user' fill_in "email", :with => "[email protected]" fill_in "password",...
agarrow
1

votes
1

answer
435

Views

Rails 3.2: Switching from Rspec to Test::Unit

I created a new Rails 3.2.x application with the -T option for no tests because I wanted to use Rspec for testing. Now I want to revert it back to Test::Unit. How can I do that such that all of the rake tasks work, and new scaffolds are generated with Test::Unit instead of RSpec test shells?
Jay Godse
1

votes
1

answer
486

Views

Why is my rspec test failing for user confirmation?

Here is the failing test: context "when password does not match confirmation" do before { build(:user, :password_confirmation => 'mismatch') } it { should_not be_valid } end I am using Factory Girl's build method for this test suite. My user model: class User < ActiveRecord::Base attr_accessible :em...
Amit Erandole
1

votes
1

answer
2.6k

Views

RSpec test that a class method calls an instance method

I'm looking to test that a class method calls a specific instance method. Is there any way to do this? This is the best I've got, but it fails. describe '#foo' do let(:job) { create :job } it 'calls job.bar' do job.should_receive(:bar) Job.foo end end I need to be sure that the right instance of job...
MechaChad
1

votes
2

answer
352

Views

spork/guard reload schema

I use spork and guard to speed up the test suite in my Rails 3.2 application. However the tests in guard behave strange after adding a new migration: they act as they don't know about the changes in schema, even though I run rake db:migrate before. They start to behave correctly when I stop guard an...
mrzasa
1

votes
1

answer
833

Views

Installing gem without the internet availability

Yesterday I tried to install rspec gem on a system which was not connected to internet, so this is what I did- I downloaded the gem for rspec using the command gem install rspec and on command prompt its showing 5 gem inside the package - (system with internet conn) diff-lcs-1.1.3, rspec-2.12.0, rsp...
swapnesh
1

votes
2

answer
362

Views

Rspec does not seem to be targeting the correct controller

Getting really bizarre rspec behavior in one of my controller specs. It's best to illustrate. In rubymine, when I set a breakpoint, this happens: #rspec test describe Api::V1::UsersController do let(:user) { FactoryGirl.create(:user) } describe "#show" do it "responds successfully" do get 'show', i...
David Nix

View additional questions