Я новичок в разработке, основанной на тестировании TDD, и я пытаюсь выполнить свои первые несколько тестов, и у меня не получается этот тест, даже когда я знаю, что заголовок четко указан на странице
response.should have_selector("title", :content => "Ruby on Rails | Home")
любые идеи о том, что я делаю неправильно и / или есть ли где-нибудь в Интернете список помощников rspec Это рельсы 3.2.1 приложение между прочим
Обновить тест не удается с этой ошибкой
Failures:
1) PagesController GET 'home' should have the right title
Failure/Error: response.should have_selector("title", :content => "Ruby on Rails | Home")
expected following output to contain a <title>Ruby on Rails | Home</title> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
# ./spec/controllers/pages_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
Finished in 0.17154 seconds
4 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:11 # PagesController GET 'home' should have the right title
my application.html.haml равно
!!! Strict
%html{ :xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang'=>"en", :lang=>"en" }
%head
%title= "Ruby on Rails | Home"
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
= yield
1) PagesController GET 'home' should have the right title
Failure/Error: page.should have_selector("title", :content => "Ruby on Rails | Home")
NameError:
undefined local variable or method `page' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x000001011b22e8>
# ./spec/controllers/pages_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
Finished in 0.16401 seconds
4 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:11 # PagesController GET 'home' should have the right title
UPDATE
вот мой спецификационный контроллер со всеми прохожденными тестами, за исключением рассматриваемого
require 'spec_helper'
describe PagesController do
describe "GET 'home'" do
subject { page }
it "returns http success" do
get 'home'
response.should be_success
end
it "should have the right title" do
get 'home'
page.should have_selector("title", :content => "Ruby on Rails | Home")
end
it "should render template" do
get 'home'
response.should render_template('pages/home')
end
end
describe "GET 'contact'" do
it "returns http success" do
get 'contact'
response.should be_success
end
end
describe "GET 'about'" do
it "returns http success" do
get 'about'
response.should be_success
end
end
end
Еще одно обновление ... вот мой источник, когда я просматриваю источник на странице
<!DOCTYPE html>
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Ruby on Rails | Home</title>
<link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/pages.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/pages.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="fi3Er/VJrzhpb5FPAcT0DYT9RFNu1oW3p4og5dg+jFc=" name="csrf-token" />
</head>
<body>
<h1>Pages#home</h1>
<p>
Find me in app/views/pages/home.html
</p>
</body>
</html>
да еще одно обновление
gem 'rails', '3.2.1'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'rspec-rails', '2.8.1'
end
group :test do
gem 'rspec', '2.8.0'
gem 'webrat', '0.7.3'
end
gem 'jquery-rails'
gem "haml", "~> 3.1.4"