2012-06-13 37 views
1

我在我的黃瓜測試一個正則表達式設立簡單黃瓜測試問題

Then /I should see "(.*)" before "(.*)"/ do |string1, string2|

,並在下面的語句我說

在我的正則表達式是

regexp = /#{string1}.*#{string2}/m

這是該方案

Scenario: sort movies alphabetically 
    When I follow "Movie Title" 
    Then I should see "2001: A Space Odyssey" before "Aladdin" 

但是當我運行測試我收到此錯誤

expected: /2001: A Space Odyssey.*Aladdin/m 
     got: "<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Rotten Potatoes!</title>\n<link href=\"/assets/application.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\">\n<script src=\"/assets/application.js\" type=\"text/javascript\"></script>\n</head>\n<body>\n<h1 class=\"title\">Rotten Potatoes!</h1>\n<div id=\"main\">\n<h1>All Movies</h1>\n<form accept-charset=\"UTF-8\" action=\"/movies\" id=\"ratings_form\" method=\"get\">\n<div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\"></div>\n<input id=\"title_sort\" name=\"title_sort\" type=\"hidden\" value=\"true\">\n\nInclude:\nG\n<input id=\"ratings_G\" name=\"ratings[G]\" type=\"checkbox\" value=\"1\">\nPG\n<input id=\"ratings_PG\" name=\"ratings[PG]\" type=\"checkbox\" value=\"1\">\nPG-13\n<input id=\"ratings_PG-13\" name=\"ratings[PG-13]\" type=\"checkbox\" value=\"1\">\nNC-17\n<input id=\"ratings_NC-17\" name=\"ratings[NC-17]\" type=\"checkbox\" value=\"1\">\nR\n<input id=\"ratings_R\" name=\"ratings[R]\" type=\"checkbox\" value=\"1\"><input id=\"ratings_submit\" name=\"commit\" type=\"submit\" value=\"Refresh\">\n</form>\n\n<table id=\"movies\">\n<thead><tr>\n<th class=\"hilite\"><a href=\"/movies?&amp;sort=title\" id=\"title_header\">Movie Title</a></th>\n<th>Rating</th>\n<th><a href=\"/movies?&amp;sort=release_date\" id=\"release_date_header\">Release Date</a></th>\n<th>More Info</th>\n</tr></thead>\n<tbody id=\"movielist\"></tbody>\n</table>\n<a href=\"/movies/new\">Add new movie</a>\n\n</div>\n</body>\n</html>\n" (using =~) 
    Diff: 
    @@ -1,2 +1,44 @@ 
    -/2001: A Space Odyssey.*Aladdin/m 
    +<!DOCTYPE html> 
    +<html> 
    +<head> 
    +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    +<title>Rotten Potatoes!</title> 
    +<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css"> 
    +<script src="/assets/application.js" type="text/javascript"></script> 
    +</head> 
    +<body> 
    +<h1 class="title">Rotten Potatoes!</h1> 
    +<div id="main"> 
    +<h1>All Movies</h1> 
    +<form accept-charset="UTF-8" action="/movies" id="ratings_form" method="get"> 
    +<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"></div> 
    +<input id="title_sort" name="title_sort" type="hidden" value="true"> 
    + 
    +Include: 
    +G 
    +<input id="ratings_G" name="ratings[G]" type="checkbox" value="1"> 
    +PG 
    +<input id="ratings_PG" name="ratings[PG]" type="checkbox" value="1"> 
    +PG-13 
    +<input id="ratings_PG-13" name="ratings[PG-13]" type="checkbox" value="1"> 
    +NC-17 
    +<input id="ratings_NC-17" name="ratings[NC-17]" type="checkbox" value="1"> 
    +R 
    +<input id="ratings_R" name="ratings[R]" type="checkbox" value="1"><input id="ratings_submit" name="commit" type="submit" value="Refresh"> 
    +</form> 
    + 
    +<table id="movies"> 
    +<thead><tr> 
    +<th class="hilite"><a href="/movies?&amp;sort=title" id="title_header">Movie Title</a></th> 
    +<th>Rating</th> 
    +<th><a href="/movies?&amp;sort=release_date" id="release_date_header">Release Date</a></th> 
    +<th>More Info</th> 
    +</tr></thead> 
    +<tbody id="movielist"></tbody> 
    +</table> 
    +<a href="/movies/new">Add new movie</a> 
    + 
    +</div> 
    +</body> 
    +</html> 
    (RSpec::Expectations::ExpectationNotMetError) 
    ./features/step_definitions/movie_steps.rb:33:in `/I should see "(.*)" before "(.*)"/' 
    features/sort_movie_list.feature:26:in `Then I should see "2001: A Space Odyssey" before "Aladdin"' 

有什麼建議?我假設我的錯誤是在我的正則表達式,但我找不到一個工作的解決方案。

+0

我試圖編輯你的問題來編碼格式錯誤。在預計的單詞前面放上四個空格,看起來好多了。 – Ivan

+0

Woops,現在修復:) – Anconia

+1

這是真的,你的網頁沒有2001或阿拉丁。我想也許錯誤是在你的視圖模板中?它看起來只是輸出「電影標題」。你能發佈你的視圖代碼嗎? – Ivan

回答

2

好,很高興有幫助!回答這樣我可以得到堆棧溢出的業力...您的模板需要列出電影或您的方案需要填充您正在尋找的數據。