2016-07-13 1 views
0

환상적인 wisper gem을 사용하여 모델 (Rails 4.1)의 변경 사항에 대응하고 있습니다. 위에서 알 수 있듯이 여기 broadcast레일 "테스트"환경에서 포함되지 않은 메소드에 액세스 할 수 있습니다.

Class Transaction < ActiveRecord::Base 
    #include Wisper::Publisher 
    after_save { broadcast(:transaction_saved)} 

end 

Wisper::Publisher 모듈에 의해 제공되는 방법의 포함은 주석. 때문에 모든이에

는,이 같은 테스트는 "broadcast 방법이없는"에 대해 불평없이 전달할 수있는 방법을 이해하고 있지 않다 : 예상 development/production 환경으로

require 'test_helper' 
class TransactionTest < ActiveSupport::TestCase 
    include GeneralHelper # this doesnt include any other module 
    def setup 
    @tr = Transaction.create(...) 
    end 
    def test_transaction_method 
    @tr.update_attributes(amount:100) 
    end 
end 

이 방법은

누락에 대해 불평

- 업데이트 test/test_helper.rb

ENV["RAILS_ENV"] ||= "test" 
require File.expand_path('../../config/environment', __FILE__) 
require 'rails/test_help' 
require "mocha/mini_test" 
require 'minitest/reporters' 
Minitest::Reporters.use!(
    Minitest::Reporters::ProgressReporter.new, 
    ENV, 
    Minitest.backtrace_filter) 

# Capybara and poltergeist integration 
require "capybara/rails" 
require "capybara/poltergeist" 
Capybara.javascript_driver = :poltergeist 


class ActiveSupport::TestCase 
    ActiveRecord::Migration.check_pending! 
    include FactoryGirl::Syntax::Methods 

    # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 
    # 
    # Note: You'll currently still have to declare fixtures explicitly in integration tests 
    # -- they do not yet inherit this setting 
    fixtures :all 

    # Add more helper methods to be used by all tests here... 
    def assert_valid(model, msg = nil) 
    msg = message(msg) { "Expected #{model} to be valid, but got errors: #{errors}." } 
    valid = model.valid? 
    errors = model.errors.full_messages.join(', ') 
    assert valid, msg 
    end 
end 
,363,210

Gemfile

source 'https://rubygems.org' 

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.1.13' 

# Use pg as the database for Active Record 
gem 'pg' 

# Use SCSS for stylesheets 
gem 'sass-rails'#, '~> 4.0.2' 

# 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' 
gem 'jquery-turbolinks' 

#gem 'bootstrap-sass' 
gem 'font-awesome-rails' 
gem 'simple-line-icons-rails' 
gem 'active_link_to' 

gem 'country_select', github: 'stefanpenner/country_select' 
gem 'chronic' 

gem 'will_paginate'#, '3.0.4' 
gem 'will_paginate-bootstrap' 


#Editable 
#gem 'bootstrap-editable-rails' 
#Encryption 
gem 'aes' 

# 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', '~> 1.2' 

group :doc do 
    # bundle exec rake doc:rails generates the API under doc/api. 
    gem 'sdoc', require: false 
end 
# Use ActiveModel has_secure_password 
gem 'bcrypt', '~> 3.1.7' 

gem 'redis' 
gem 'firebase' 
# Use unicorn as the app server 
gem 'puma' 

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

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

gem 'recipient_interceptor' 

group :test, :development do 
    #gem 'rspec-rails' 
    #gem 'rspec-its' 
    gem 'pry' 
    gem 'pry-nav' 
    gem 'pry-rails' 
end 

gem 'nokogiri' 
gem 'faker' 
gem 'haml' 
gem 'slim' 
gem 'rack-mini-profiler' 
gem 'newrelic_rpm' 
#gem 'appsignal' 

group :test do 
    gem 'capybara' 
    #gem 'capybara-webkit' 
    gem 'factory_girl_rails' 
    #gem "connection_pool" 
    #gem "launchy" 
    gem "minitest" 
    gem "minitest-reporters" 
    gem "mocha" 
    gem "poltergeist" 
    #gem "shoulda" 
end 

gem 'axlsx' 
gem 'prawn' 
gem 'active_model_serializers' 

gem 'card-rails' 

gem 'rails_12factor', group: :production 
#gem 'twitter-typeahead-rails', :git => "git://github.com/yourabi/twitter-typeahead-rails.git" 
gem 'rack-cors', :require => 'rack/cors' 

gem 'sidekiq' 
gem 'rest-client' 
gem 'nest' 
gem 'redic' 
gem 'fog' 
gem 'aws-sdk' 
gem 'twilio-ruby' 
gem 'react-rails', '~> 1.0' 
gem 'wisper', '2.0.0.rc1' 
gem 'ruby-prof' 
gem 'le' 
gem 'mechanize' 
gem 'mandrill-api' 
gem 'business_time' 
gem 'paleta' 
gem "aftership", "~> 4.3.1" 
+0

Gemfile을 게시하십시오. 게시물 test_helper.rb – 7stud

+0

@ 7stud 네가 맞아, 끝났어! – lllllll

+0

미래의 독자들이 질문을 해결하지 않고 대답을 게시하는 것이 도움이됩니다. –

답변

0
당신은 확실히이 할 수있는

:

module MyWisper 
    def broadcast 
    puts 'hello' 
    end 
end 

class SomeClass 
    include MyWisper 
end 

SomeClass.new.broadcast 

--output:-- 
hello 

을하지만 당신이 할 수 있습니다 : 그래서 어딘가에 모두가 필요에

module MyWisper 
    def broadcast 
    puts 'hello' 
    end 
end 

def broadcast 
    puts 'hi' 
end 

class SomeClass 
    #include MyWisper 
    broadcast 
end 


--output:-- 
hi 

을, 당신은 글로벌 방송을 요구하고있다() 메소드를 테스트 환경에 추가하십시오.

+0

그러나 '방송'방법은 위스퍼의 방송이하는 일을 정확히 수행하고 있습니다. 게다가이 메소드에는'transaction_saved' 매개 변수도 함께 제공됩니다 ('transaction_saved' 브로드 캐스트를 수신하는 observer 메소드 내에서 디버깅을 테스트했습니다). 따라서'Wisper :: Publisher'는'test' env에 대해서만 빠져있는 곳에 있어야합니다. – lllllll

+0

클래스/모듈 외부에서 메서드를 정의하지 않으면 모든 것을 채 웁니다. – Kris

관련 문제