我的 rspec 代码有问题。我写了一些测试。我使用如下语法:主题 {page} 然后我想以这种风格编写测试:它 {should have_content()} 但是当我运行 rspec 它显示错误:
Failure/Error: it{ should have_content("Post associated with #{category.name}") }
NoMethodError:
undefined method `it' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x00000007c86ea8>
这是我的所有文件:
require 'spec_helper'
describe "Categories Pages" do
subject {page}
let(:user) {FactoryGirl.create(:user)}
before {sign_in user}
let(:category) {FactoryGirl.create(:category)}
let(:p3 ) {FactoryGirl.create(:post, user: user, content: "Foo", title: "Bar", category: category)}
describe "Categories show page" do
before do
visit post_path(p3)
click_link 'Test Category'
end
it "should has elements" do
current_path.should == category_path(category)
it{ should have_content("Post associated with #{category.name}") }
expect(page).to have_content(p3.content)
expect(page).to have_link(p3.title, href: post_path(p3))
expect(page).to have_content(p3.comments.count)
expect(page).to have_link(p3.category.name, href: category_path(p3.category))
expect(page).to have_link(p3.user.name, href: user_path(user))
expect(page).to have_link('All Categories', href: categories_path)
expect(page).to have_title(full_title('Test Category'))
end
end
describe "Categories index page" do
before do
visit post_path(p3)
click_link 'Test Category'
click_link "All Categories"
end
it "should have elements" do
expect(page).to have_link('Test Category', href: category_path(category))
expect(page).to have_selector('h1', text: 'All Categories')
expect(page).to have_title(full_title('All Categories'))
end
end
end
请帮忙。