title: how to test javascript within rspec capybara?
body: <p>I use a javascript library - clipboardjs - for copying input field values to system clipboard.</p>
  
  <p>In my application.js:</p>
  
  <pre><code>function addressClipboard() {
    new Clipboard('.address-copy', {
        text: function(trigger) {
            var addressString = "";
            addressString += $('#addresses_attributes_0_street').val() + "\n" +
               $('#addresses_attributes_0_city').val() + "\n";
            addressString = addressString.trim();
            return addressString;
        }
    })
  };
  </code></pre>
  
  <p>I like to test the functionality with rspec &amp; capybara.</p>
  
  <p>address_spec.rb:</p>
  
  <pre><code>    it "checks the copied values when clicking the copy-to-clipboard link", :js do
        new_address = build(:address)
        visit new_address_path
        fill_in "person_addresses_attributes_0_street", with: new_address.street
        fill_in "person_addresses_attributes_0_city", with: new_address.city
        click_link(I18n.t('helpers.copy_to_clipboard'))
        # Pseudocode:
        expect(page.execute_script("addressClipboard()")).to eq([new.address.street,new.address.city].join)
  </code></pre>
  
  <p>Is there a way to access the javascript variable addressString and compare it to the address attributes (eg. new_address.street) within rspec?</p>