Setting default_url_options in test environment doesn't seem to work

rails default_url_options
rspec host!

I've put the following code into my config/environments/test.rb file:

config.action_mailer.default_url_options = { :host => "localhost:3000" }

however when I run my tests, all routes use I'm trying to work with an API that won't accept as a valid callback URI, so I need to change this to properly receive the API response. Any idea why this isn't working? (I'm using RSpec, Guard, and Spork in my testing suite).

EDIT: Possibly relevant - this is being done inside of a controller spec.

EDIT2: It seems that it changes after a request is made via get, post, etc. Running the following code within the test:

Rails.logger.debug users_url
get ''
Rails.logger.debug users_url

would produce the following output:

...get request related response here

Nowadays you can just set them in your test.rb like so:

Rails.application.routes.default_url_options[:host]= 'localhost:3000' 

Default_url_options is being ignored · Issue #1275 · rspec/rspec , It works fine for non-feature specs but doesn't work for feature specs. is set to Rails.application.default_url_options[:host] in test environment. The Integration test should get the default_url_options from ApplicationController For me, using the 'setup' method in an integration test to set the app.default_url_options errors, because the attribute doesn't exist.

Rails.application.routes.default_url_options[:host]= 'localhost:3000'

In the developemnt.rb / test.rb, can be more concise as following:

Rails.application.configure do
  # ... other config ...

  routes.default_url_options[:host] = 'localhost:3000'

How to get rspec to respect test env default_url_options : rails, config.action_mailer.default_url_options = { host: 'http://localhost:3000' } Does anyone know if I can make it so rspec uses what is defined in my test environment? I suspect your tests aren't actually running with the test environment. Secondly, anyone know any good guides how to set up SES with SNS on AWS to get  Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true The reason your proposed solution in #1276 appears to work is simply because the example's default_url_options is nil and so it falls back to the routes which you have customized in the spec/rails_helper.rb.

How are you running your tests? Maybe appending RAILS_ENV=test might help.

Setting default_url_options in a test environment does not work , Rails Environment Settings; Using Initializer Files; Initialization events True by default in development and test environments, and false in production mode. and sets config.action_mailer.default_url_options to be { protocol: 'https' } . key columns are named id (and this configuration option doesn't need to be set.)  Configure unit tests by using a .runsettings file. 10/03/2019; 10 minutes to read +17; In this article. Unit tests in Visual Studio can be configured by using a .runsettings file. . For example, you can change the .NET version on which the tests are run, the directory for the test results, or the data that's collected during a test

Configuring Rails Applications, As far as I can tell, it doesn't get fixed because the RSpec teams The reason is that ActionController::TestCase ignores normal settings of default_url_options in ApplicationController or your config/environments/test.rb . Environments overview. 06/08/2020; 6 minutes to read; In this article. An environment is a space to store, manage, and share your organization's business data, apps, and flows. It also serves as a container to separate apps that might have different roles, security requirements, or target audiences.

Using default_url_options in RSpec with Rails 5, Why does this happen and how can it be fixed? It isn't possible to dynamically set an environment variable but you can detect a review isn't configured in development or test. protocol = Rails.application.config.force_ssl ? Hi, I'm writing xunit tests against class libraries targeting dnxcore50. I've added environment variables to the launchSettings.json file via the Project's properties page, but when I debug the unit test the environment variables are not

Dynamically setting Rails default_url_options in Heroku review apps, unless Rails.env.test? default_url_options = {. host:,. protocol: Gitlab.config.gitlab.protocol,. script_name:  Explicit per-test setup is far easier for other readers of the test to reason about the environment the test will run in. It is possible to override this setting in individual tests by explicitly calling jest.mock() at the top of the test file. verbose [boolean] Default: false. Indicates whether each individual test should be reported during

Set default_url_options in test environments too (2c905797 , Now let's work on the configs setup. Locate configs/environments/development.rb​. We want to configure  Software Center always uses your default setting. Users can change this filter, but Software Center doesn't persist their preference. Set the Default application view as either Tile view or List view. If a user changes this configuration, Software Center persists the user's preference in the future. Software deployment

  • Accepting based on @parhamr's comment.
  • Works in Rails 5.1.4. Saved me a lot of time.
  • What do you mean by appending RAILS_ENV=test? ENV["RAILS_ENV"] is "test" already. As mentioned, I'm running the tests with RSpec, Guard, and Spork. I just run bundle exec guard and it loads up the Spork server, which automatically runs the RSpec tests.