Expect a Case-Insensitive Match

We had a testing issue this week when a button’s text save changes! was rendering as SAVE CHANGES!, due to the CSS property text-transform: uppercase. How do you test that? One technique is to use RSpec’s match method, and include case insensitivity with i (explored earlier here): > button_text = "foo" => "foo" > expect(button_text).to match("FOO") RSpec::Expectations::ExpectationNotMetError: expected "foo" to match "FOO" # stuff > expect(button_text).to match(/FOO/i) => true We ultimately hard coded the expectation to match("FOO"), because allowing fOo and FoO seemed too permissive. But it remains an option.

January 5, 2016

Testing Edit Forms

Today I found a way to assert that an edit form’s inputs include a record’s saved data. I think it strikes a good balance between broad and narrow scope. # spec/features/user_edits_kit_spec.rb within 'form' do expect(page).to have_selector("input[value='Default copy.']") end This asserts that some content is inside an input field in the form, rather than just anywhere on the page. You can narrow the scope as needed.

November 17, 2015

Don’t miss my next essay

Hear from me immediately when I post: no ads, unsubscribe anytime.