Rails, Devise, Rspec: Undefined method ‘sign_in’

Did you recently upgrade to RSpec 3 like I did? This is from the RSpec 3 documentation: Automatically Adding Metadata RSpec versions before 3.0.0 automatically added metadata to specs based on their location on the filesystem. This was both confusing to new users and not desirable for some veteran users. In RSpec 3, this behavior … Read more

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

Test ActiveModel::Serializer classes with Rspec

Assumptions This answer assumes you have the rspec-rails, active_model_serializers and factory_girl_rails gems installed and configured. This answer also assumes you have defined a factory for the Sample resource. Serializer spec For the current version(0.10.0.rc3) of active_model_serializers at the time of writing, ActiveModel::Serializer classes do not receive to_json and are , instead, wrapped in an adapter … 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 avoid deprecation warning for stub_chain in RSpec 3.0?

In order to get rid of the warning with your code as-is, you’ll have to explicitly enable the should syntax in your config: RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = [:should, :expect] end end The replacement syntax for stub_chain is: allow(object).to receive_message_chain(:one, :two, :three).and_return(:four) expect(object.one.two.three).to eq(:four) More information about this and its usage … Read more

Is DatabaseCleaner still necessary with Rails system specs?

You do not need the DatabaseCleaner gem. Here’s a quick summary of steps you need: Remove capybara-selenium gem and database_cleaner gem Add selenium-webdriver gem Make sure you are using Rails 5.1.5 or later. Earlier versions of Rails 5.1 had a defect in ActionDispatch::SystemTesting::Server that caused problems (fixed here). In your rails_helper file, set config.use_transactional_fixtures = … Read more