ruby-on-railsrubyruby-on-rails-6system-testingactiondispatch

How do you set the server port in Rails system tests?


The Rails server starts on a different port every time you run the system tests.

Is there any way to specify which port this should be and not have it change on every run?

I would like to test clicking a link from an ActionMailer message in my system test. I need to specify a host in my test environment config file for this and I need a static port number for that.


Solution

  • Already answered here: https://stackoverflow.com/a/6807498/338859

    If using Capybara you can set the port in the spec_helper.rb like so:

    Capybara.server_port = 1234
    

    Also see this blog post, it also has some mentions for emails: System of a test: Proper browser testing in Ruby on Rails