Προς το περιεχόμενο

Ruby on Rails rspec testing


Προτεινόμενες αναρτήσεις

Δημοσ.

Έχω κάνει στο Ruby on Rails ένα project που έχει την εξής δομή:
1415385933.png

Στο αρχείο app/controllers/pages_controller.rb έχω τον εξής απλό κώδικα:


class PagesController < ApplicationController

  def home

  end



  def contact

  end

end

Και έχω δημιουργήσει το path /spec/controllers/pages_constoller_spec.rb που έχει το περιεχόμενο:

require 'spec_helper'



describe PagesController do

render_views

  describe "GET 'home'" do

   it "should be successful" do

     get 'home'

     response.should be_success

   end

  end



  describe "GET 'contact'" do

    it "should be successful" do

     get 'contact'

     response.should be_success

    end

  end

end

Και όταν τρέχω:

rspec spec/controllers/pages_controller_spec.rb

Παίρνω τα εξής errors:


Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- spec_helper (LoadError)

    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

    from /home/pcmagas/Kwdikas/Ruby/Rails/sample_app/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'

    from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'

    from /usr/local/bin/rspec:23:in `load'

    from /usr/local/bin/rspec:23:in `<main>'

Έχετε ιδέα τι φταίει;

Tον κώδικα τον πήρα από το βιβλίο "Ruby On Rails 3 Tutorial - Michael Hartl"

 

Δημοσ.

Λειπει το gem spec_helper ή εχεις λαθος εκδοση. Δοκιμασε να τρεξεις με:

bundle exec rspec spec/controllers/pages_controller_spec.rb

Αν δε τρεξει, δες το Gemfile κ προσθεσε ή αλλαξε την εγγρφη

gem 'spec_helper', '>= 1.8'

μετα δωσε την εντολη

bundle install

και δοκιμασε απ την αρχη

Δημοσ.

Το gemfile μου είναι:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',       

group: :development do
gem 'webrat'
gem 'rspec', '>-3.1.0'
gem 'rspec-rails'
gem 'ZenTest', '4.4.1'
gem 'autotest-rails'
end

gem 'spec_helper'
gem 'rspec-core'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]


Kαι όταν εκτελώ:

bundle exec rspec spec/controllers/pages_controller_spec.rb

Παίρνω τα εξής errors:

Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]
Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]
Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]
Could not find gem 'spec_helper (>= 0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.

  • 1 μήνα μετά...
Δημοσ. (επεξεργασμένο)

Μετά από πολύ καιρό το ξαναέποιασα το θέμα και παίρνω τα εξής errors:

pcmagas@dimitris:~/Kwdikas/Ruby/Rails/sample_app$ rspec ./spec/controllers/pages_controller_spec.rb 
Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]
/home/pcmagas/Kwdikas/Ruby/Rails/sample_app/spec/spec_helper.rb:29:in `block (2 levels) in <top (required)>': undefined method 
`include_chain_clauses_in_custom_matcher_descriptions=' for #<RSpec::Matchers::Configuration:0x00000001897ff0> (NoMethodError)
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:592:in `expect_with'
        from /home/pcmagas/Kwdikas/Ruby/Rails/sample_app/spec/spec_helper.rb:21:in `block in <top (required)>'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core.rb:81:in `configure'
        from /home/pcmagas/Kwdikas/Ruby/Rails/sample_app/spec/spec_helper.rb:17:in `<top (required)>'
        from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1072:in `block in requires='
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1072:in `each'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1072:in `requires='
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:103:in `block in process_options
_into'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:102:in `each'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:102:in `process_options_into'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration_options.rb:22:in `configure'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:95:in `setup'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
        from /usr/local/bin/rspec:23:in `load'
        from /usr/local/bin/rspec:23:in `<main>'

Ενώ το αρχείο pages_controller_spec.rb:

require_relative '../spec_helper'

describe PagesController do
render_views
  describe "GET 'home'" do
   it "should be successful" do
     get 'home'
     response.should be_success
   end
  end

  describe "GET 'contact'" do
    it "should be successful" do
     get 'contact'
     response.should be_success
    end
  end
end

Ενώ μέσω Bundle:

pcmagas@dimitris:~/Kwdikas/Ruby/Rails/sample_app$ bundle exec rspec spec/
Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]
Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]
Invalid gemspec in [/var/lib/gems/1.9.1/specifications/ZenTest-4.11.0.gemspec]: Illformed requirement ["< 3.0, >= 1.8"]
/home/pcmagas/Kwdikas/Ruby/Rails/sample_app/spec/controllers/pages_controller_spec.rb:3:in `<top (required)>': uninitialized co
nstant PagesController (NameError)
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
        from /var/lib/gems/1.9.1/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
        from /usr/local/bin/rspec:23:in `load'
        from /usr/local/bin/rspec:23:in `<main>'
Επεξ/σία από PC_MAGAS

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...