1

我在黄瓜测试中设置了一个正则表达式

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

在下面的声明中我说

page.body.should =~ regexp

我的正则表达式在哪里

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"'

有什么建议么?我假设我的错误出现在我的正则表达式中,但我找不到有效的解决方案。

4

1 回答 1

2

好的,很高兴有帮助!回答这样我就可以获得堆栈溢出业力......您的模板需要列出电影,或者您的场景需要填充您正在寻找的数据。

于 2012-06-13T22:50:06.293 回答