jasmine / jasmine-gem

Jasmine ruby gem
682 stars 274 forks source link

Can you specify individual sources files to be used in individual spec files? #281

Closed jmzbond closed 7 years ago

jmzbond commented 7 years ago

Just started with Jasmine, so probably just lacking info here. Also tried to email the group but didn't have permission.

I understand you put (like Rspec) the spec file in the javascripts folder with a naming convention of <file_name_to_be_tested>_spec.js That's great!

So I have spec/javascripts/orders_new_spec.js

I've discovered that I can use the above to test EITHER of the files below:

app/assets/javascripts/orders/new.js
app/assets/javascripts/orders_new.js

But for someone like me who does have a somewhat complex file directory... I need a way to differentiate the two... Right now of course the jasmine.yml looks like this:

src_files:
  - assets/orders/new.js
  - assets/orders_new.js

But since there's ONE yml file for all specs, it doesn't serve as a differentiator.

Is there some way to, in the spec file itself do it? E.g.,

# /spec/javascripts/orders/new_spec.js
require 'assets/orders/new.js` # and ignore jasmine.yml
describe...

# /spec/javascripts/orders_new_spec.js
require 'assets/orders_new.js` # and ignore jasmine.yml
describe...
slackersoft commented 7 years ago

Jasmine (especially in the browser) doesn't have any relationships between which spec file tests which implementation file. If you have a subset of files that can't be loaded in the same page as some other subset of files, you probably want to have multiple jasmine.yml files and use the JASMINE_CONFIG_PATH environment variable (looks like we missed that in the docs) to pick the right one when running your tests. This would mean you need to run two (or more) jasmine:ci tasks to run all of your specs.

The other option would be to refactor/rework your implementations so that all of the files can be loaded into the browser at the same time and just instantiate the underlying objects in your specs.

Hope this helps. Thanks for using Jasmine! Closing this.