简体   繁体   中英

Michael Hartl Rails Tutorial Chapter 3 RSpec Syntax Errors

I am attempting to work my way through Hartl's Rails tutorial. In working through Chapter 3.2.1, I have now run into the following two errors when attempting

bundle exec rspec spec/requests/static_pages_spec.rb

Both are syntax errors:

I:/Programs/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load': C:/Users/Anastasia/RubymineProjects/sample_app/spec/requests/static_pages_spec.rb:3: syntax error, unexpected keyword_do_block (SyntaxError)

C:/Users/Anastasia/RubymineProjects/sample_app/spec/requests/static_pages_spec.rb:12: syntax error, unexpected keyword_end, expecting $end

I've gone into each of the two files, and I am not seeing an actual syntax error:

static_pages_spec.rb contains the following code:

require 'spec_helper'

RSpec.describe "StaticPages", do

  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
  end
end

All "do's" seem to have a matching "end."

spec_helper.rb contains the following code:

RSpec.configure do |config|

  config.include Capybara: :DSL

end

Again, the "do" and "end" seem to match.

Note: I am very new to coding. My previous experience is html/css-related. I'm currently going through a free trial of Ruby Mine while going through this tutorial, and I can't help but wonder if perhaps it would be better to simply start over with just a text editor like SublimeText, since using RM means I'm not only working to learn Ruby and Rails, but also RM. There are things I really like about RM (I'm a visual person by nature, so having something that's more visually appealing is good, but also I like the gem installation interface, which makes it easy not only to install gems, but also to read their documentation). Another downside to using RM is the version differences between the tutorial and what RM comes bundled with (Ruby 1.9.3 versus 2.0.0, etc) which has led to me electing to leave off the version listings in gemfiles to avoid creating bizarre conflicts (I may be wrong in thinking that will be an issue, but it made logical sense in my mind).

The Capybara gem is installed and is in the gemfile, so I don't think that's the issue (could be wrong, though). I'm sure I'm just missing something really simple, but I can't for the life of me see what it is.

Any advice or assistance would be appreciated!

You have a typo in your code

 RSpec.describe "StaticPages", do

This line shouldn't have that comma

RSpec.describe "StaticPages" do

if the ends match it is almost surely a comma. "programming is like writing a book except if you have one extra comma on page 126 the whole thing makes no sense."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM