require 'spec_helper' describe Arachni::Browser::Javascript::DOMMonitor do before( :all ) do @url = Arachni::Utilities.normalize_url( web_server_url_for( :dom_monitor ) ) end before( :each ) do @browser = Arachni::Browser.new @javascript = @browser.javascript @browser.load @url @dom_monitor = described_class.new( @javascript ) end def load( path ) @browser.load "#{@url}/#{path}" end let(:javascript) { @javascript } subject { @dom_monitor } after( :each ) do Arachni::HTTP::Client.reset @browser.shutdown end describe '#class' do it "returns #{described_class}" do subject.class.should == described_class end end describe '#initialized' do it 'returns true' do subject.initialized.should be_true end end it 'adds _arachni_events property to elements holding the tracked events' do load '/elements_with_events/listeners' javascript.run( "return document.getElementById('my-button')._arachni_events").should == [ [ 'click', 'function (my_button_click) {}' ], [ 'click', 'function (my_button_click2) {}' ], [ 'onmouseover', 'function (my_button_onmouseover) {}' ] ] javascript.run( "return document.getElementById('my-button2')._arachni_events").should == [ [ 'click', 'function (my_button2_click) {}' ] ] javascript.run( "return document.getElementById('my-button3')._arachni_events").should be_nil end describe '#digest' do it 'returns a string digest of the current DOM tree' do load '/digest' subject.digest.should == '