I'd like to create a test to make sure my third party tools (js scripts) are present (for example, to make sure nobody in the team removed it by accident!)
Here are 2 javascript third party tool that are loaded on my homepage view whose presence i'd like to 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 are my rspec test (I'm using Capybara with webkit driver)
describe "third party tools are present inside source code", js: true do
it 'should have js trackings' do
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 does not work as it always pass (!), but i'm a rookie with this kind of tests using regular expressions and I'm not even sure that's the right way to do it.
thanks for any help, Mathieu
Aucun commentaire:
Enregistrer un commentaire