Skip to content

Instantly share code, notes, and snippets.

@DmytroVasin
Last active February 28, 2017 19:07
Show Gist options
  • Save DmytroVasin/06044a753ce1eadc09864ce204ef79c0 to your computer and use it in GitHub Desktop.
Save DmytroVasin/06044a753ce1eadc09864ce204ef79c0 to your computer and use it in GitHub Desktop.
Extend Rspec to include additional matcher.
describe "Assets", type: :feature, js: true do
describe "application.js" do
it "does not include page-specific content" do
visit root_path
expect("d3").to be_undefined_in_js
expect("moment").to be_undefined_in_js
end
end
private
RSpec::Matchers.define :be_undefined_in_js do
match do |actual|
evaluate_script("typeof #{actual} === 'undefined'") == true
end
failure_message do |actual|
"expected JS not to include #{actual}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment