Zeff

Zeff

Sustainable Web Development with Ruby on Rails:

Title: Sustainable Web Development with Ruby on Rails: Regex incorrect (testing Helpers section)

This code fails:

“# test/helpers/application_helper_test.rb

class ApplicationHelperTest < ActionView::TestCase
test “styled_widget_id” do
rendered_component = styled_widget_id(“1.23”)

→ regexp = %r{
→ <span # match a span tag
→ [^>]* # ignore anything that isn’t >
→ > # match the > to close the opening tag
→ .* # anything at all in here (e.g. other tags)
→ 1.23 # the widget ID we expect, escaping the dot
→ .* # anything after it (e.g. other tags)
→ # closing span tag
→ }x

assert_match regexp, rendered_component
 assert rendered_component.html_safe?
end

end

The line:
→ [^>]* # ignore anything that isn’t >
should be:
→ .* # ignore anything that isn’t >

First Post!

davetron5000

davetron5000

Author of Rails, Angular, Postgres, and Bootstrap

I’m surprised this fails. The book executes this code when it’s run and that regexp should be correct.

Without the %r{..}x formatting, the regular expression in the book is:

regexp = /<span[^>]*>.*1\.23.*<\/span>/

And this does match the two strings in the book:

> regexp.match?('<span style="font-family: monospace">1.23</span>')
=> true
> regexp.match?('<span class="mono">1.23</span>') 
=> true

I did notice that copying and pasting from the PDF doesn’t copy the regular expression properly. Unfortunately, the tools I use to build the book result in weird uncopyable code blocks.

Can you try copying the code straight from the .zip files and see what happens?

Popular Pragmatic Bookshelf topics Top

herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
New
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New