Skip to content

Instantly share code, notes, and snippets.

@themoxman
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themoxman/9727242 to your computer and use it in GitHub Desktop.
Save themoxman/9727242 to your computer and use it in GitHub Desktop.

Questions

VCR with AJAX

Suitor app, text_spec.rb.

feature 'Reddit Text Message Alerts' do
  let(:heading) { "PrompText" }
  let(:subreddit) { "romance" }
  let(:my_number) { "6107420826" }

  scenario "send that special someone the top /r/romance post", feature: true do
    VCR.use_cassette('twilio_message') do
      visit "/"

      # verify the page has correct heading text
      expect(page).to have_content heading

      # fill in the phone number and subreddit form fields
      fill_in 'subreddit', with: subreddit
      fill_in 'number', with: my_number

      # submit the form
      click_button 'Send Message!!'

      # check for successful 'message sent' notice
      expect(page).to have_content 'Aww yea, message is sent!!'
    end
  end
end

It passes, but if I log it with tail -f log/test.log, I see the request is an HTML, not JS request. This seems strange as I have remote: true set on the submission form.

VCR w JS

  scenario "try to send a message with an invalid subreddit", js: true, feature: true do
    VCR.use_cassette('davemoxistheman_js') do
      visit "/"

      # invalid subreddit
      fill_in 'subreddit', with: "davemoxistheman"
      fill_in 'number', with: my_number

      # submit the form
      click_button 'Send Message!!'

      # check for correct error message
      expect(page).to have_content "Uh oh, that subreddit doesn't exist. Try another!"
    end
  end
end

Capybara w JS and Hidden Form Fields

# new version
  # THIS IS NOT A VALID TEST
  # for some reason, the 'hidden' form field is not hidden when I do save_and_open_page
  # so, the spec passes without even testing that the JS show/hide element works.
  # also, when I enable JS (with js: true), the spec fails. says it can't find
  # 'collection[name]' which clearly exists...
  scenario "Edit a Collection", feature: true, js: true do
    @user.collections.create( name: "Marketing + Sales", description: "All that jazz." )

    visit root_path

    expect(page).to have_content "Marketing + Sales"

    all('.right.icon').last.click

    # there are multiple 'collection[name]' fields and 'save' buttons on the
    # page. restrict which one we fill in to avoid the 'ambiguous match' error
    within '.clearfix' do
      fill_in 'collection[name]', with: 'Marketing and Sales'
      click_button 'Save'
    end

    expect(page).to have_content("Marketing and Sales")
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment