I'm following this tutorial but it keeps failing saying "undefined method `new' for Redcarpet:Module". I have gem "redcarpet" in my Gemfile. The piece of code that is failing:
Redcarpet.new(#post.content).to_html
Okay, it looks like Redcarpet 2 has completely changed the API. The following works:
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
:autolink => true, :space_after_headers => true)
raw markdown.render(#post_content.content)
Related
I have a number of helper classes stored under my spec/support directory which i reuse in a number of tests. For example, foo_helper.rb
class FooHelper
def self.stub_thing
Foo.any_instance.stub(:thing)
Foo.any_instance.stub(:thing=)
end
end
Foo is used in a number of tests, so i would just require ../spec/support/foo_helper.rb in each spec i wanted to be able to use FooHelper.stub_thing. This all worked fine in RSpec 2.x
Having upgraded to RSpec 3.1, I'm seeing the following depreciation warning:
Using `any_instance` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from app/spec/support/foo_helper.rb:4:in `stub_thing'.
So, having added rspec-actvemodel-mocks to my Gemfile:
gem 'rspec-rails', '~> 3.1'
group :development, :test do
gem 'rspec-activemodel-mocks', '~> 1.0'
end
And following the documentation, i changed my code to:
class FooHelper
def self.stub_thing
allow_any_instance_of(Foo).to receive(:thing)
allow_any_instance_of(Foo).to receive(:thing=)
end
end
Which, then causes my tests to fail with the following error:
Failure/Error: FooHelper.stub_thing
NoMethodError:
undefined method `allow_any_instance_of' for FooHelper:Class
# ./spec/support/foo_helper.rb:4:in `stub_amount'
# ./spec/models/parent_model.rb:33:in `block (2 levels) in <top (required)>'
How can allow_any_instance_of not be defined, when any_instance and stub are?!
I ran into this as well after updating RSpec in one of our apps. For anyone else running into it, and who hasn't explicitly selected the should syntax, just add extend RSpec::Mocks::ExampleMethods to the beginning of the class or module in which you're trying to use these methods.
allow_any_instance_of is only enabled when the expect syntax is enabled, per http://www.rubydoc.info/github/rspec/rspec-mocks/RSpec/Mocks/ExampleMethods:allow_any_instance_of. Presumably, you configured RSpec to work only with the older should syntax.
I just ran into this issue as well. Are you by any chance calling it from a before :all block? Apparently this isn't allowed, because it worked after moving it to a before :each.
Hope that helps!
This is basically a rails 3 version of this question. Short of parsing it myself, how can I get the components (controller, action, parameters) from a URL string?
The method ActionController::Routing::Routes#recognize_path has been deprecated, and I can't get the one it's been replaced with to work the same way:
1.9.3p125 :019 > ActionDispatch::Routing::RouteSet.recognize_path('/accounts/new', {:method => :get})
NoMethodError: undefined method `recognize_path' for ActionDispatch::Routing::RouteSet:Class
which makes sense since it's not a static method. Looking at the source didn't enlighten me either. Any pointers would be welcome.
EDIT:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Rails 3.2.3
This works for me (Ruby 1.9.2, Rails 3.1.0):
Rails.application.routes.recognize_path('/accounts/new', {:method => :get})
I have a Garb model:
class Visits
extend Garb::Model
metrics :visits, :new_visits, :pageviews
dimensions :month, :hostname, :network_domain, :country, :region, :source
end
And I have this line in my controller:
for visit in Visits.results(profile, :start_date => (Date.today-numdays), :filters => { :hostname.eql => "#{#brand.subdomain}.mysite.com" })
This has worked fabulously. But all of a sudden, even though none of the actual code has been modified:
NoMethodError in AnalyticsController#index
undefined method `eql' for :hostname:Symbol
What could be causing this?
For some reason the garb/lib/support.rb is not loaded anymore. Did you put :require => false to the garb gem line in Gemfile?
Did you install right_http_connection-1.3.0 gem? It will cause the garb/lib/support.rb not to be loaded if you require 'right_http_connection' before 'garb'. If that you could fix this by installing a lower right_http_connection, such as right_http_connection-1.2.4.
After all you can use command
find /Your/gems/installed/dir -name "*.rb" -print | xargs grep '\<support\>' | grep 'require'
to find what files cause your garb/lib/support.rb was not loaded anymore.
This link http://kayakjang.github.com/2011/05/27/garb.html may be helpful to you for this problem.
I fixed this by cutting and pasting the contents of garb/lib/support.rb into the environment.rb file. Not ideal, I know. But I don't know what gem update modified Symbol, and this works. Props to Roman for pointing me in the right direction.
I'm testing the waters with Rails and I'm stuck with this simple test:
I have this code in spec/routing/routing_spec.rb
require 'spec_helper'
describe "Accessing the root domain" do
it "should route to home#index" do
{ :get => '/' }.
should route_to(:controller => 'home', :action=>'index')
end
end
This fails with the following error:
Failure/Error: { :get => '/' }.
Expected block to return true value.
# ./spec/routing/routing_spec.rb:7:in `block (3 levels) in <top (required)>'
What's wrong in my code?
I ran into this opaque error message as well with Rails 3 and Ruby 1.9.2. The reason in my case was that I was using an old version of minitest that ships with Ruby, and in that version the assert_block method (invoked by assert_recognizes in ActionDispatch::Assertions::RoutingAssertions) does not display the error message (how the routing params didn't match). The fix for me was to add minitest to my Gemfile and install it via bundler:
group :test do
gem "minitest", ">= 2.6.1" # The minitest version that ships with Ruby is old and has bugs
end
I would then get a more understandable error message:
The recognized options <{"action"=>"index",
"controller"=>"publish/product_versions",
"product_id"=>"ipad_app"}> did not match <{"controller"=>"publish/product_versions",
"action"=>"indexx",
"product_id"=>"ipad_app"}>, difference: <{"action"=>"indexx"}>.
Expected block to return true value.
This seems like it should work, so my guess would be that there is a configuration problem. Difficult to know what it is, though, without seeing more of the app. Also, the failure says it happens on line 7, but it references line 5 in the code above, so there might be something else in the file that is gumming up the works.
Also, the error message is confusing because the expectation is written on two lines. If you wrote it on one line, you'd see the whole statement. Not that that would help narrow down this problem, other than to help you understand that it's not trying to treat { :get => '/' } as a block.
HTH,
David
This happened with me because my controller rendered the wrong view. I fixed the logic of my controller method and everything worked fine.
The problem is that I keep getting
NoMethodError (undefined method `paginate' for #<Class:0x1e3dec0>):
activerecord (3.0.3) lib/active_record/base.rb:1008:in `method_missing'
Below is the code snippet I am including and any help in fixing my problem. I am using will_paginate-rails3 at the moment.
def list
#users = User.paginate :per_page => 10, :page => 1
end
in user_controller.rb
and also
<!-<%= link_to 'Previous page', { :page => #users.previous_page } if #users.previous_page %>-->
in my views.html.
Could someone please point me in the right direction?
Did you use the Rails 3 branch of will_paginate? It's here:
https://github.com/mislav/will_paginate/tree/rails3
Specify it in your Gemfile like this:
gem 'will_paginate', '~> 3.0.beta'
then install it like this:
bundle install