2012-12-19 90 views
-1

我得到一個語法錯誤 我的測試代碼語法錯誤,意想不到的tIDENTIFIER,期待keyword_end

require 'spec_helper' 
describe "User pages" do 
subject { page } 
describe "signup page" do 
before { visit signup_path } 

it { should have_selector('h1', text: 'Sign up') } 
it { should have_selector('title', text: full_title('Sign up')) } 
end 

describe "profile page" do 
let(:user) { FactoryGirl.create(:user) } 

before { visit user_path(user) } 
it { should have_selector('h1', text: user.name) } 
it { should have_selector('title', text: user.name) } 
end 

describe "signup" do 
before { visit signup_path } 
let(:submit) { "Create my account" } 
describe "with invalid information" do 
it "should not create a user" do 
expect { click_button submit }.not_to change(User, :count) 
end 
end 
describe "with valid information" do 
before do 
fill_in "Name", with: "Example User" 
fill_in "Email" with: "[email protected]" 
fill_in "password" with: "foobar" 
fill_in "confirmation" with: "foobar" 
end 


it "should create a user" do 
expect { click_button submit }.to change(User, :count).by(1) 
end 
end 
end 


end 

和錯誤日誌

/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load': /home/ritesh/projects/sample_app/spec/requests/user_pages_spec.rb:30: syntax error, unexpected tIDENTIFIER, expecting keyword_end (SyntaxError) 
fill_in "Email" with: "[email protected]" 
        ^
/home/ritesh/projects/sample_app/spec/requests/user_pages_spec.rb:31: syntax error, unexpected tIDENTIFIER, expecting keyword_end 
fill_in "password" with: "foobar" 
        ^
/home/ritesh/projects/sample_app/spec/requests/user_pages_spec.rb:32: syntax error, unexpected tIDENTIFIER, expecting keyword_end 
fill_in "confirmation" with: "foobar" 
         ^
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files' 
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map' 
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files' 
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run' 
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run' 
    from /home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun' 

請幫我如何糾正它!

回答

3

在路上你的代碼看起來會幫你找到語法問題以驕傲;在這種情況下,第一個參數後面的fill_in行中的逗號。

require 'spec_helper' 

describe "User pages" do 
    subject { page } 

    describe "signup page" do 
    before { visit signup_path } 

    it { should have_selector('h1', text: 'Sign up') } 
    it { should have_selector('title', text: full_title('Sign up')) } 
    end 

    describe "profile page" do 
    let(:user) { FactoryGirl.create(:user) } 
    before { visit user_path(user) } 

    it { should have_selector('h1', text: user.name) } 
    it { should have_selector('title', text: user.name) } 
    end 

    describe "signup" do 
    before { visit signup_path } 
    let(:submit) { "Create my account" } 

    describe "with invalid information" do 
     it "should not create a user" do 
     expect { click_button submit }.not_to change(User, :count) 
     end 
    end 

    describe "with valid information" do 
     before do 
     fill_in "Name",   with: "Example User" 
     fill_in "Email",  with: "[email protected]" 
     fill_in "password",  with: "foobar" 
     fill_in "confirmation", with: "foobar" 
     end 

     it "should create a user" do 
     expect { click_button submit }.to change(User, :count).by(1) 
     end 
    end 
    end 
end 
4

好像你忘了昏迷或二繞線30 ...(前「與」)

+0

我不想用我的答案來竊取你的雷霆;我只是**有**重新格式化OP的代碼。 – deefour

+0

而你完全有權這樣做; )Upvoted你的痛苦,通過擊中「標籤」鍵。 – Raindal

相關問題