How do I get an ENV variable set for rspec?

If you just need to set environment variables, you can either set them from command-line: SOMETHING=123 SOMETHING_ELSE=”this is a test” rake spec Or you could define the following at the top of your Rakefile or spec_helper.rb: ENV[‘SOMETHING’]=123 ENV[‘SOMETHING_ELSE’]=”this is a test” If they don’t always apply, you could use a conditional: if something_needs_to_happen? ENV[‘SOMETHING’]=123 ENV[‘SOMETHING_ELSE’]=”this … Read more

POSTing raw JSON data with Rails 3.2.11 and RSpec

As far as I have been able to tell, sending raw POST data is no longer possible within a controller spec. However, it can be done pretty easily in a request spec: describe “Example”, :type => :request do params = { token: 0 } post “/user/reset_password”, params.to_json, { ‘CONTENT_TYPE’ => ‘application/json’, ‘ACCEPT’ => ‘application/json’ } … Read more

expected true to respond to true?

From rspec 3.0, be_true is renamed to be_truthy and be_false to be_falsey The behavior has not changed. So (nil).should be_falsey (false).should be_falsey will pass, and (anything other than nil or false).should be_truthy will also pass From the changelog 3.0.0.beta1 / 2013-11-07 Rename be_true and be_false to be_truthy and be_falsey. (Sam Phippen)

Rails 5, Rspec: Environment data not found in the schema

New Rails 5 command to generate binstubs: rails app:update:bin Allows me to run the solution as the error suggested: bin/rails db:environment:set RAILS_ENV=test Tip from @max comment: If you are using database_cleaner and this error keeps popping up then change your config to: DatabaseCleaner.clean_with( :truncation, except: %w(ar_internal_metadata) )

Rails 3.1, RSpec: testing model validations

CONGRATULATIONS on you endeavor into TDD with ROR I promise once you get going you will not look back. The simplest quick and dirty solution will be to generate a new valid model before each of your tests like this: before(:each) do @user = User.new @user.username = “a valid username” end BUT what I suggest … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)