Note that there are some explanatory texts on larger screens.

plurals
  1. POError message in online Rails course on URL Shortener
    primarykey
    data
    text
    <p><a href="http://www.trybloc.com" rel="nofollow">TryBloc</a> has an online course that teaches Rails among other programming languages. There's a <a href="http://www.trybloc.com/courses/url_shortener" rel="nofollow">course on URL Shortening</a>, and I'm a bit puzzled by the rspec test that is failing on the fourth lesson (Storing the short codes).</p> <p>This is supposed to be something simple, and each lesson builds upon the previous ones. I feel as though I'm overlooking something small, but can't spot it. The error from rspec isn't helping either. How can I fix this and pass this fourth lesson? Am I reading the instruction correctly?</p> <p>The instruction:</p> <blockquote> <p>In your first challenge, we asked you to return only a random string of 5 digits.</p> <p>CHALLENGE Set the code you generate as a key in Redis so that we remember the same key for a domain.</p> </blockquote> <p>The example given:</p> <pre><code>REDIS.set("12345", "google.com") REDIS.get("12345") # google.com REDIS.exists("12345") # true, the key exists </code></pre> <p>The Code that can be modified:</p> <pre><code>require 'sinatra' configure do require 'redis' require 'uri' REDISTOGO_URL = ENV["REDISTOGO_URL"] uri = URI.parse(REDISTOGO_URL) REDIS = Redis.new(:host =&gt; uri.host, :port =&gt; uri.port, :password =&gt; uri.password) end get "/" do "Try going to /shorten?url=http://www.google.com" end # yourapp.com/?url=http://google.com get "/shorten" do # Write your code below to create a random number. random_number = (1..9).to_a.shuffle.sample(5).join("") REDIS.set(random_number, params[:url]) end # Please leave this extra space at the bottom </code></pre> <p>The error:</p> <blockquote> <p>F..</p> <p>Failures:</p> <p>1) URL Shortener returns a short code</p> <pre><code>Failure/Error: last_response.body.should =~ /(\d){5}/ expected: /(\d){5}/ got: "http://google.com" (using =~) Diff: @@ -1,2 +1,2 @@ -/(\d){5}/ +http://google.com # ./spec:42:in `block (2 levels) in &lt;top (required)&gt;' </code></pre> <p>Finished in 0.4169 seconds</p> <p>3 examples, 1 failure</p> <p>Failed examples:</p> <p>rspec ./spec:40 # URL Shortener returns a short code</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload