Stubbing Devise in rSpec and Rails3

I found that it is now pretty easy to do this. There was a problem with rspec2 and devise, but is now solved. I guess you would need to update your gems. Then you can write require ‘spec_helper’ describe DoStuffController do include Devise::TestHelpers before (:each) do @user = Factory.create(:user) sign_in @user end describe “GET ‘index'” … Read more

mock Rails.env.development? using rspec

There is a much better way described here: https://stackoverflow.com/a/24052647/362378 it “should do something specific for production” do allow(Rails).to receive(:env) { “production”.inquiry } #other assertions end This will provide all the functions like Rails.env.test? and also works if you just compare the strings like Rails.env == ‘production’

Capybara: Unable to find css

I had the exact issue yesterday. Capybara was automatically ignoring the input due to it being invisible. I solved it with the following: find(‘#agreement’, :visible => false).click You can also add the following to env.rb to enable Capybara to interact with all hidden elements: Capybara.ignore_hidden_elements = false

How to test puts in rspec

I think the best way is to use rspec build in output matcher https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/output-matcher Fore example, this is your class class MakeIt def awesome(text) puts “Awesome #{text}” end end and your test describe MakeIt do describe ‘#awesome’ do it ‘prints awesome things’ do expect do MakeIt.new.awesome(‘tests’) end.to output(‘Awesome tests’).to_stdout end it ‘does not print not … Read more

Cuke4Nuke or SpecFlow?

(I might be biased because I am involved with SpecFlow, but here my thoughts…) Cuke4Nuke is very close to Cucumber. This promises a lot of advantages: Compatibility Getting new features from Cucumber when Cucumber evolves (at least in theory, but language support is an example for this) Being a real part of the Cucumber community … Read more

How to Send RubyMine Notifications to Growl?

May be This code will help you # -*- ruby -*- module Autotest::RedGreen Autotest.send(:alias_method, :real_ruby, :ruby) Autotest.send(:define_method, :ruby) do |*args| real_ruby + %[ -rrubygems -e “require ‘redgreen'” ] end # Clean the output so other modules can work correctly Autotest.add_hook :ran_command do |at| at.results.each do |r| r.gsub!(“\033[31m”, “”) r.gsub!(“\033[32m”, “”) r.gsub!(“\033[33m”, “”) r.gsub!(“\033[0m”, “”) end … Read more

RSpec partial match against a nested hash

You are able to use and nest the hash_including method for these matchers. Using your example, you can rewrite your test code to look like: expect(response_json).to include(hash_including({ employee: hash_including(jobs_count: 0) })) (or if response_json is a single object, replace include with match) This will also work when dealing with .with constraints, for example: expect(object).to receive(:method).with(hash_including(some: … Read more

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