2013-08-11 2 views
0

내 rspec 코드에 문제가 있습니다. 나는 몇 가지 시험을 쓴다. 내가 좋아하는 구문을 사용합니다 대상 {페이지} 다음 나는이 스타일로 테스트의 작성 : 원함 {have_content한다()}하지만 난 RSpec에 그 쇼의 오류 실행하면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 

도와주세요.

답변

1

나는 it 블록을 중첩 할 수 있다고 생각하지 않습니다. 주변 it 블록에서이 라인을

it{ should have_content("Post associated with #{category.name}") } 

를 당겨 그에게 describe 블록의 독립 테스트를합니다.

+0

나는 모든 테스트를 리펙토링하며 현재 작동 중입니다. 도와 주셔서 감사합니다:) –

3

it을 다른 it 안에 넣을 수 없습니다.

문제점은이 라인이다

it{ should have_content("Post associated with #{category.name}") } 

단순히 it 제거하거나 다른 IT 블록 외부로 이동.

page.should have_content("Post associated with #{category.name}") 

테스트 당 하나의 어설 션을 갖는 것이 좋습니다. Check better specs

관련 문제