0

rspec コードに問題があります。私はいくつかのテストを書きます。次のような構文を使用します: subject {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

助けてください。

4

2 に答える 2