ruby - Test presence of javascript code/snippet with rspec capybara (Rails 4) -


i'd create test make sure third party tools (js scripts) present (for example, make sure nobody in team removed accident!)

here 2 javascript third party tool loaded on homepage view presence i'd test:

<script type="text/javascript"> var clicky_site_ids = clicky_site_ids || []; xxxxxxxxxxxxxxxxxxxxxxxxx (function() {   var s = document.createelement('script');   s.type = 'text/javascript';   s.async = true;   s.src = '//static.getclicky.com/js';   ( document.getelementsbytagname('head')[0] || document.getelementsbytagname('body')[0] ).appendchild( s ); })(); </script>  <script src="//src.melvinize.io/r.js"></script> 

here rspec test (i'm using capybara webkit driver)

describe "third party tools present inside source code", js: true        'should have js trackings'       visit(root_path)       all('script').find { |s| s[:src].match /getclicky\.js$/ }.should_not be_nil       all('script').find ("//static.getclicky.com/js").should_not be_nil        all('script').find ("//src.melvinize.io/r.js").should_not be_nil     end     end 

my test not work pass (!), i'm rookie kind of tests using regular expressions , i'm not sure that's right way it.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -