2010-06-25 13 views
5

Non sono sicuro che si tratti di un problema di Rails 3 o RSpec 2, ma non riesco a ottenere un test del controller standard funzionante - sembra che il il metodo 'get' non può essere trovato.Impossibile ottenere il test del controller funzionante con RSpec 2 e Edge Rails 3

Ho un test di controllo che assomiglia a questo (nome discrepancies_controller_spec.rb in spec/controllers directory):

require 'spec_helper' 

describe DiscrepanciesController do 
    before :each do 
    Discrepancy.delete_all 
    end 

    it "resolves a discrepancy" do 
discrepancy = Discrepancy.create(:my_number=>"12345", :status=>"Open") 

get :resolve, :id => discrepancy.id 

retrieved_discrepancy = Discrepancy.find_by_my_number("12345") 
retrieved_discrepancy.status.should == "Resolved" 
    end 
end 

(sì, sono consapevole delle implicazioni di sicurezza di modifica dei dati con un HTTP/GET - che è un questione a parte ...)

Quando eseguo con rastrello, ottengo il seguente errore:

1) DiscrepanciesController resolves a discrepanc 
    Failure/Error: Unable to find C to read failed line 
    undefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1:0xc9170d0 @__memoized={}> 
    # ./spec/controllers/discrepancies_controller_spec.rb:38 (ignore the line number, commented out code was removed from the sample) 
    # C:/Users/Patrick_Gannon/.bundle/ruby/1.8/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:212:in `inject' 
    # C:/Ruby187/bin/rake:19:in `load' 
    # C:/Ruby187/bin/rake:19 

riesco a testare l'azione di controllo istanziando direttamente il controller e chiamando direttamente l'azione del controller, e funziona, ma è brutto perché devo prendere in giro cose come respond_to e params.

Altre informazioni pertinenti: eseguo Windows 7 a 32 bit, Ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-wingw32], edge Rails 3 e MongoDB/MongoMapper. Ecco la mia lista delle gemme installati (via 'gioiello fascio' - tutte le mie gemme installati sono stati installati da Bundler)

  • abstract (1.0.0)
  • ActionMailer (3.0.0.beta4)
  • actionpack (3.0.0.beta4)
  • activemodel (3.0.0.beta4)
  • ActiveRecord (3.0.0.beta4)
  • ActiveResource (3.0.0.beta4)
  • ActiveSupport (3.0.0.beta4)
  • AREL (0.4.0)
  • bcrypt-ruby (2.1.2)
  • BSON (1.0.3)
  • bson_ext (1.0.1)
  • Builder (2.1.2)
  • bundler (0.9.26)
  • Capistrano (2.5.19)
  • capibara (0.3.8 a94f99)
  • cetriolo (0.8.3)
  • cetriolo-rotaie (0.3.2 master-b 75110)
  • culerity (0.2.10)
  • database_cleaner (0.5.2 7ea99d)
  • escogitare (1.1.rc1 88ab2f)
  • diff-lcs (1.1.2)
  • erubis (2.6.5)
  • factory_girl (1.3.0)
  • factory_girl_rails (1,0)
  • falsario (0.3.1)
  • ffi (0.6.3)
  • gherkin (2.0.2)
  • highline (1.5.2)
  • i18n (0.4.1)
  • jnunemaker-validabile (1.8.4)
  • congiunta (0.3.2 11a094)
  • json_pure (1.4.3)
  • posta (2.2.5)
  • tipi mIME (1,16)
  • mongo (1.0.3)
  • mongo_mapper (0.8.2)
  • net-sCP (1.0.2)
  • net-sftp (2.0.4)
  • net-ssh (2.0.23)
  • net-ssh-Gateway (1.0.1)
  • nokogiri (1.4.2.1)
  • coraggioso (0.3.2)
  • poliglotte (0.3.1)
  • cremagliera (1.1.0)
  • montaggio a rack (0.6.6)
  • cremagliera-test (0.5.4)
  • rotaie (3.0.0. beta4 6682cc)
  • railties (3.0.0.beta4)
  • rastrello (0.8.7)
  • rspec (2.0.0.beta.13)
  • rspec-core (2.0.0.beta.13)
  • RSpec-aspettative (2.0.0.beta.13)
  • RSpec-deride (2.0.0.beta.13)
  • RSpec-rails (2.0.0.beta.13)
  • selenio WebDriver (0.0 .24)
  • term-ansicolor (1.0.5)
  • thor (0.13.6)
  • sugli alberi (1.4.8)
  • trollop (1.16.2)
  • tzinfo (0.3.22)
  • bacchetta (0.2.1)
  • operaio (0.10. 7)
  • Webrat (0.7.1)

ho anche aggiunto una dichiarazione mette nel test per mostrare ciò che sono disponibili metodi al dispositivo di prova ((methods - Object.methods).sort.inspect), e "ottenere" non è nella lista. Ecco ciò che è nella lista:

"__memoized", "__should_for_example_group__", "__should_not_for_example_group__", "_fixture_class_names", "_fixture_path", "_fixture_table_names", "_pre_loaded_fixtures", "_setup_mocks", "_teardown_mocks", "_use_instantiated_fixtures", "_use_transactional_fixtures", "_verify_mocks", "a_kind_of", "allow_message_expectations_on_nil", "an_instance_of", "any_args", "anything", "assert", "assert_block", "assert_equal", "assert_in_delta", "assert_instance_of", "assert_kind_of", "assert_match", "assert_nil", "assert_no_match", "assert_not_equal", "assert_not_nil", 
"assert_not_same", "assert_nothing_raised", "assert_nothing_thrown", "assert_operator", "assert_raise", "assert_raises", "assert_respond_to", "assert_same", "assert_send", "assert_throws", "be", "be_a", "be_a_kind_of", "be_a_new", "be_an", "be_an_instance_of", "be_close", "be_false", "be_instance_of", "be_kind_of", "be_nil", "be_true", "boolean", "build_message", "change", "described_class", "double", "duck_type", "eq", "eql", "equal", "example", "example=", "exist", "expect", "fixture_class_names", "fixture_class_names?", "fixture_path", "fixture_path?", "fixture_table_names", 
"fixture_table_names?", "flunk", "hash_including", "hash_not_including", "have", "have_at_least", "have_at_most", "have_exactly", "include", "instance_of", "kind_of", "match", "method_missing", "method_name", "mock", "mock_discrepancy", "mock_model", "no_args", "pending", "pre_loaded_fixtures", "pre_loaded_fixtures?", "raise_error", "respond_to", "run_in_transaction?", "running_example", "satisfy", "setup_fixtures", "stub_model", "subject", "teardown_fixtures", "throw_symbol", "use_instantiated_fixtures", "use_instantiated_fixtures?", "use_transactional_fixtures", "use_transactional_fixtures?" 

risposta

4

Hai una risposta a questa sulla mailing list RSpec da David Chelimsky, come segue:

Mi sorprende questa è la prima volta che questo ha messo a punto rspec-2, ma eccoci qui :)

Questo è un bug di path-separator che risolverò nella prossima versione. Per ora, è possibile farlo nelle specifiche del controller:

describe DiscrepanciesController do 
    include RSpec::Rails::ControllerExampleGroup 

Che dovrebbe funzionare correttamente.

Se si vuole fare una soluzione più globale, aggiungere questo alla vostra configurazione spec_helper:

RSpec.configure do |c| 
    c.include RSpec::Rails::ControllerExampleGroup, :example_group => { :file_path => /\bspec[\\\/]controllers[\\\/]/ } 
end 
Problemi correlati