Closed campbecf closed 8 years ago
@campbecf have you read this section of the README?
Does it apply to your use case?
We run our tests on CI through Rake, which seems to have a RAILS_ENV defined even when we run ember tests through it.
When we run rspec it runs under the ci environment
@campbecf do you mean there is a new (non-{test,development,production}
) environment?
Does RAILS_ENV=CI
?
This block of code might be what you need.
In CI
, could you override the EMBER_ENV environment variable to be whatever you'd like?
We already override the EMBER_ENV to 'ci' with rspec, but that doesn't compile an index.html due to not being a development or test environment. We could manually call a compile first, but doing that before every rspec run seems a little tedious.
We've been trying to upgrade from ember-cli-rails 0.3.x to 0.7.x.
@campbecf what makes overriding EMBER_ENV=ci
preferable to EMBER_ENV=test
being inherited from RAILS_ENV=test
?
When we run rspec it runs under the
ci
environment
Does this apply to when you run rspec
locally (i.e. what would normally be RAILS_ENV=test
)?
This is the relevant section of our environment.js (trimmed slightly)
if (environment === 'test') {
// Testem prefers this...
ENV.baseURL = '/';
ENV.locationType = 'none';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
ENV['ember-cli-mirage'] = { enabled: true };
ENV['simple-auth'].store = 'simple-auth-session-store:ephemeral';
} else {
ENV['ember-cli-mirage'] = { enabled: false };
}
};
Here is one of our rspec helpers:
RSpec.configure do |config|
config.before(:all, type: :feature) do
ENV['EMBER_ENV'] = 'ci'
end
end
What this allowed in version 0.3.x of ember-cli-rails was when we ran ember test it would execute under the test environment block in environment.js above. When we ran rspec it would execute under the 'ci' environment and default into the else block in environment js. Rspec would automatically generate the index.html via ember-cli-rails.
With ember-cli-rails 0.7.x calling rspec will only compile the index.html for the test environment. In app.rb the call to test? checks for env.to_s == 'test'. I'm pretty new to Ruby so I could be misunderstanding an easy way to solve this.
What are the intentions behind this code block:
RSpec.configure do |config|
config.before(:all, type: :feature) do
ENV['EMBER_ENV'] = 'ci'
end
end
For what it's worth, ember-cli-rails
will pass the entire shell environment along to the ember
subprocess.
If you're trying to enable Mirage for ember test
, but disable Mirage for type: :feature
RSpec tests, what do you think about something like this:
RSpec.configure do |config|
config.before(:all, type: :feature) do
ENV['EMBER_CLI_MIRAGE'] = 'false'
end
end
// config/environment.js
if (environment === 'test') {
// This will evaluate to `true` when the environment variable is set to `'true'`
// (if you need to override it from Rails) or
// when it is `undefined` (when run outside of Rails via `ember test`).
//
// When run from within Rails or Rake, RSpec's `before(:all, type: :feature)`,
// it will evaluate to `false`
var enableMirage = process.env.EMBER_CLI_MIRAGE !== 'false';
ENV['ember-cli-mirage'] = { enabled: enableMirage };
}
If an approach like this doesn't work, please let me know.
This appears to work, thanks!
We need ember-cli-mirage turned off for rspec, development, and production. We do this through our environment.js
When we run
ember test
it runs under the test environment. This turns mirage on.When we run
rspec
it runs under the ci environment. This turns mirage off, but now ember-cli-rails won't compile the index and calls@build.wait!
which just seems to loop.How would you advise to resolve this?