Questions
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.
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