Why not use shared ActiveRecord connections for Rspec + Selenium?

Actually there are issues with it. If you use the gem mysql2, for example, you’ll start seeing some errors like: Mysql2::Error This connection is still waiting for a result Please use this instead. It was written by Mike Perham, all credits to him. class ActiveRecord::Base mattr_accessor :shared_connection @@shared_connection = nil def self.connection @@shared_connection || ConnectionPool::Wrapper.new(:size … Read more

Testing modules in RSpec

The rad way => let(:dummy_class) { Class.new { include ModuleToBeTested } } Alternatively you can extend the test class with your module: let(:dummy_class) { Class.new { extend ModuleToBeTested } } Using ‘let’ is better than using an instance variable to define the dummy class in the before(:each) When to use RSpec let()?

iOS Tests/Specs TDD/BDD and Integration & Acceptance Testing

tl;dr At Pivotal we wrote Cedar because we use and love Rspec on our Ruby projects. Cedar isn’t meant to replace or compete with OCUnit; it’s meant to bring the possibility of BDD-style testing to Objective C, just as Rspec pioneered BDD-style testing in Ruby, but hasn’t eliminated Test::Unit. Choosing one or the other is … Read more

undefined method `get’ for #

RSpec doesn’t know that your spec is a controller spec, so your examples don’t have access to a get method. RSpec 2.x assumes that everything in the controllers directory is a controller spec. This was changed in RSpec 3: File-type inference disabled by default Previously we automatically inferred spec type from a file location, this … Read more

Rails: Missing host to link to! Please provide :host parameter or set default_url_options[:host]

You need to add the following line at every environment: config.action_mailer.default_url_options = { :host => “yourhost” } That way, it can work in all environments and could be different from environment to environment. For example: development.rb config.action_mailer.default_url_options = { :host => “dev.yourhost.com” } test.rb config.action_mailer.default_url_options = { :host => “test.yourhost.com” } production.rb config.action_mailer.default_url_options = { … Read more

How do I change the default “www.example.com” domain for testing in rails?

Integration/Request Specs (inheriting from ActionDispatch::IntegrationTest): host! ‘my.awesome.host’ See the docs, section 5.1 Helpers Available for Integration Tests. alternatively, configure it globally for request specs at spec_helper.rb level: RSpec.configure do |config| config.before(:each, type: :request) do host! ‘my.awesome.host’ end end Controller Specs (inheriting from ActionController::TestCase) @request.host=”my.awesome.host” See the docs, section 4.4 Instance Variables Available. Feature Specs (through … Read more