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.

RSpec is a behaviour-driven development (BDD) tool for Ruby programmers. BDD is an approach to software development that combines test-driven development (TDD), domain-driven design (DDD), and acceptance test-driven planning (ATDP). RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.

RSpec 2 and later site

RSpec 1 site

Resources

Books

18192 questions
7
votes
2 answers

rspec-rails controller testing with assertions and assigns

I have been using rails 5.0.0.1, am new to automation testing and using rspec-rails-3.5.2 for writing automation. I want to test some basic controller rendering functionality and instance variable assignments. Wrote a controller test case which…
Suganya
  • 652
  • 7
  • 14
7
votes
2 answers

Testing validations in model using RSpec with Rails

I'm super new to testing my app using RSpec and I'm trying to test the validation of a comment without a user and keep getting syntax errors. Here is the comment model code. class Comment < ApplicationRecord belongs_to :user belongs_to…
Jerry Hoglen
  • 111
  • 1
  • 10
7
votes
1 answer

Rails::Generator is not creating factory in spec folder

I am trying to generate a new factory inside a module and I basically required require 'rails/generators' and I am calling the command below. Notice that it creates the file inside the test folder. Rails::Generators.invoke 'factory_girl:model',…
7
votes
1 answer

Poltergeist/PhantomJS crashing in Gitlab CI

Background: My testing suite did not handle any JS functionality until recently. I started out only on my machine with a selenium-webdriver javascript driver and firefox 47.0.1 with no issues. I then migrated over to poltergeist supporting PhantomJS…
Nick Schwaderer
  • 1,030
  • 1
  • 8
  • 21
7
votes
2 answers

RSpec - how to rescue and retry the test?

We have intermittently failing tests due to Net::ReadTimeout errors. We have yet to figure out a permanent fix. For right now we want to try rescuing that specific error and re-running the test. Not a ideal solution or true fix but we need…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
7
votes
3 answers

RSpec tests failing with undefined method `validate_uniqueness_of'

With Rails 5 and RSpec 3.5, I'm getting the following error. 1) User Failure/Error: it { should validate_uniqueness_of(:auth_token)} NoMethodError: undefined method `validate_uniqueness_of' for…
alpaca
  • 1,211
  • 13
  • 23
7
votes
3 answers

Good sources for learning Cucumber and RSpec?

What are some good videos, articles, ebooks, etc for learning Cucumber and RSpec? I'm aware of the PeepCode screencasts and The RSpec Book from Pragmatic, but wasn't sure if there were any other solid resources.
Shpigford
  • 24,748
  • 58
  • 163
  • 252
7
votes
1 answer

How do I write methods that insert rspec examples?

In a bunch of rspec rails unit specifications I do something like: describe Foo do [:bar, :baz].each do |a| it "should have many #{a}" do Foo.should have_many(a) end end end For cleaner code I'd rather do something like: describe…
Mori
  • 27,279
  • 10
  • 68
  • 73
7
votes
4 answers

Rspec send_data test not passing

I can't seem to get this test to pass and I don't understand why. controller_spec.rb: require 'rails_helper' RSpec.describe QuotationRequestsController, type: :controller do describe "GET download" do it "streams the sample text as a…
chell
  • 7,646
  • 16
  • 74
  • 140
7
votes
2 answers

rspec test if method is called

I can't figure out how to write a test that will work, that also doesn't run anything in my script in the CL. When @counter is 9, it is supposed to trigger #tie_game? but it does not work. @counter is initialized to 0 and is incremented by one every…
Harry B.
  • 411
  • 1
  • 4
  • 21
7
votes
5 answers

RSpec Stubbing out Date.today in order to test a method

I want to test a method that follows one path if the current date is between Jan 1st - Aug 1st, or it follows another path if the current date is between Aug 2nd - December 31st. example: def return_something_based_on_current_date if…
Neil
  • 4,578
  • 14
  • 70
  • 155
7
votes
1 answer

How to test download image with send_file method with RSpec?

I am having difficulties with testing image download. def download_img @image = Photo.find params[:id] unless params[:id].nil? @c = Cat.find params[:cat_id] unless params[:cat_id].nil? @foo = @image.foo unless @image.nil? …
Michael
  • 125
  • 1
  • 9
7
votes
1 answer

Using RSpec to test user input with gets

I'm new to Unit Testing using RSpec and Ruby and I have a question on how to test if my code is using the gets method, but without prompting for user input. Here is the code I'm trying to test. Nothing crazy here, just a simple one…
salce
  • 409
  • 1
  • 12
  • 28
7
votes
2 answers

Changing path for integration tests on a Paperclip Attachment

The documentation for Paperclip mentions that you can change the upload path for tests by placing the following code in the test.rb environment file: Paperclip::Attachment.default_options[:path] =…
Sebastian
  • 2,154
  • 1
  • 26
  • 42
7
votes
1 answer

Rspec/FactoryGirl: changes in factory not saving in test database?

I have the following factory defined for a model: factory :page do association :user, factory: :standard_user association :post, factory: [:short_post] after :create do |model| model.post.user = model.user model.save! end end the…
L457
  • 1,002
  • 1
  • 13
  • 33
1 2 3
99
100