Hej,
mam taki głupi problem.
Otóż przy ładowaniu rspeca mam błąd:
/home/slawosz/.rvm/gems/ruby-1.8.7-p248@gemy_dla_x/gems/activesupport-2.3.5/lib/active_support/core_ext/date/calculations.rb:11:in alias_method': undefined method
+’ for class `Date’ (NameError)
W script/console (zarówno w enviroment jak i test) jest tak:
>> Date.instance_methods.sort
=> ["+", "-", "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>", "_?", "__id__", "__send__", "_dump", "`", "acts_like?", "acts_like_date?", "advance", "ago", "ajd", "amjd", "as_json", "asctime", "at_beginning_of_day", "at_beginning_of_month", "at_beginning_of_quarter", "at_beginning_of_week", "at_beginning_of_year", "at_end_of_month", "at_end_of_quarter", "at_end_of_week", "at_end_of_year", "at_midnight", "b64encode", "beginning_of_day", "beginning_of_month", "beginning_of_quarter", "beginning_of_week", "beginning_of_year", "between?", "blank?", "breakpoint", "change", "class", "class_eval", "classy_module", "clone", "copy_instance_variables_from", "ctime", "cwday", "cweek", "cwyear", "daemonize", "day", "day_fraction", "dclone", "debugger", "decode64", "decode_b", "default_inspect", "display", "downto", "dup", "duplicable?", "enable_warnings", "encode64", "end_of_day", "end_of_month", "end_of_quarter", "end_of_week", "end_of_year", "england", "enum_for", "eql?", "equal?", "extend", "extend_with_included_modules_from", "extended_by", "freeze", "frozen?", "future?", "gregorian", "gregorian?", "hash", "id", "in", "in?", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_values", "instance_variable_defined?", "instance_variable_get", "instance_variable_names", "instance_variable_set", "instance_variables", "is_a?", "is_a_without_multiple_args?", "it", "italy", "its", "jd", "julian", "julian?", "kind_of?", "last_month", "last_year", "ld", "leap?", "load_with_new_constant_marking", "mday", "meta_def", "meta_eval", "metaclass", "metaclass_eval", "method", "methods", "midnight", "minus_with_duration", "minus_without_duration", "mjd", "mon", "monday", "month", "months_ago", "months_since", "new_start", "newsg", "next", "next_month", "next_week", "next_year", "nil?", "not_in?", "ns?", "numeric?", "object_id", "os?", "past?", "plus_with_duration", "plus_without_duration", "present?", "pretty_inspect", "pretty_print", "pretty_print_cycle", "pretty_print_inspect", "pretty_print_instance_variables", "private_methods", "protected_methods", "public_methods", "readable_inspect", "remove_subclasses_of", "require", "require_association", "require_dependency", "require_library_or_gem", "require_or_load", "respond_to?", "returning", "send", "sg", "silence_stderr", "silence_stream", "silence_warnings", "since", "singleton_methods", "start", "step", "strftime", "subclasses_of", "succ", "suppress", "taguri", "taguri=", "taint", "tainted?", "tap", "to_a", "to_date", "to_datetime", "to_default_s", "to_enum", "to_formatted_s", "to_json", "to_param", "to_query", "to_s", "to_time", "to_yaml", "to_yaml_properties", "to_yaml_style", "today?", "tomorrow", "try", "type", "unloadable", "untaint", "upto", "wday", "weekday?", "with_options", "workday?", "xmlschema", "yday", "year", "years_ago", "years_since", "yesterday"]
Natomiast dodając linijkę w
/home/slawosz/.rvm/gems/ruby-1.8.7-p248@gemy_dla_x/gems/activesupport-2.3.5/lib/active_support/core_ext/date/calculations.rb
p
[code=ruby]module ActiveSupport #:nodoc:
module CoreExtensions #:nodoc:
module Date #:nodoc:
# Enables the use of time calculations within Date itself
module Calculations
def self.included(base) #:nodoc:
# debug
p Date.instance_methods.sort
base.extend ClassMethods
base.instance_eval do
p self.class
alias_method :plus_without_duration, :+
alias_method :+, :plus_with_duration
alias_method :minus_without_duration, :-
alias_method :-, :minus_with_duration
end
end[/code]
i uruchamiając testy (spec spec/, rake spec) istotnie nie ma metody + w tablicy.
Co ciekawe, jak robię rake test (jest parę starych testów z generatora to debug z railsów uruchamia się 2 razy - raz pokazuje metody z + a drugi raz już bez + i jest błąd jak na początku.
Podejrzewam, że coś się wcina i ‘nadpisuje’ klasę Date. Moje pytanie - jak to wyśledzić? Jakieś hooki w stylu method_added itp?
Pozdrawiam,
Sławosz