I'm using the latest ruby 1.9.3-head and recently whenever I run rspec
(2.2+) I get the following error:
I have seen others have run into this issue, but to resolve it just
rolled back to a previous version of rspec or it there a better way?
ruby-1.9.3-head/gems/rspec-core-2.3.1/lib/rspec/core/ho
http://github.com/kristianmandrup/rspec-action_view
---
require 'spec_helper'
module MyView
module Tab
def tab_for(clazz, &block)
content = with_output_buffer(&block)
content_tag :li, content, :class => clazz
end
end
module Say
def hello(clazz, &block)
conten
hould match /kristian/
view.hello('david') { 'hello' }.should match /david/
with_action_view do |view|
view.with_template(%{
<%= tab_for('kristian') { 'hello' } %>
}).should match /hello/
end
end
end
Enjoy!
On Aug 23, 8:
t; do
it "works" do
ActionViewTester.tests MyViewHelper, MyOtherViewHelper
ActionViewTester.new do |helper|
helper.tab_for('kristian') { 'hello' }.should match /kristian/
helper.hello('david') { 'hello' }.should match /david/
I found this at: http://github.com/rspec/rspec-rails
describe EventsHelper do
describe "#link_to_event" do
it "displays the title, and formatted date" do
event = Event.new("Ruby Kaigi", Date.new(2010, 8, 27))
# helper is an instance of ActionView::Base configured with the
#
I wonder if I can just "stub out" #with_output_buffer to yield the
block immediately, and then assume it will work just as well in a
Rails view template?
class MyView < ActionView::Base
attr_accessor :current_user
def with_output_buffer
yield
end
end
I found this:
http://stackoverflow.com/questions/197164/how-do-i-test-rails-block-helpers-with-rspec
it 'should do something' do
helper.some_block_helper { the_block_code }.should
end
but not sure how to use it
I have a module which is extended on top of ActiveView::Base
module My
I am trying to test methods I have added to ActionView::Base through a
Rails 3 plugin.
Basically, I have been trying to test it "outside of Rails" if
possible, that is, to only load the bare minimum functionality.
Here is my Rails view with a custom method #area added, which uses
#with_output_buff
Looking at Ryan B's CanCan for inspiration
require 'rspec'
require 'rspec/autorun'
require 'active_support'
require 'active_record'
require 'action_controller'
require 'action_view'
require 'rails3_plugin_toolbox'
RSpec.configure do |config|
config.mock_with :rr
end
---
require "spec_helper"
I have been thinking that there must be some better ways of doing
Rails plugin development than my current approach. Currently I tend to
have my plugin in one location as a gem and then link to it from some
fresh Rails 3 app, from the vendor/plugins folder, with a symlink.
Then I have to carry arou
Spec your generated Ruby code files
code-spec at: http://github.com/kristianmandrup/code-spec
Spec your file structure (files, dirs, symlinks)
file-spec at: http://github.com/kristianmandrup/file-spec
More to come...
___
rspec-users mailing list
rspec
Just released 0.5.0, a pretty stable release with a large rspec test
suite to show it off and ensure it works as it should :)
On Aug 11, 6:02 pm, Kristian Mandrup
wrote:
> Now with an almost complete test suite to ensure it all works as it
> should and to demonstrate how to use it.
> T
To learn Rails, checkout: http://railsnotes.com/rails-3/
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
Now with an almost complete test suite to ensure it all works as it
should and to demonstrate how to use it.
The DSL is better than ever!
describe 'model_generator' do
# include Rails model helpers for ActiveRecord
# available:
# Other ORM options - :mongo_mapper, :mongoid and :data_mapper
1)
If your app name is "nice-app", make your directory like this
railsprojects/nice-app
2)
First update rubygems and perhaps use rvm (ruby version manager)
http://railscasts.com/episodes?page=3
See railscast 200 and 201. Bundler can also be used for Rails 2 I
think ;)
Which version of Rails
describe 'migration_generator' do
include RSpec::Rails::Orm::ActiveRecord
include RSpec::Rails::Migration
...
end
Didn't quite feel right. So I made it prettier DSL like using the
solution below ;)
class Class
def use_orm orm
class_eval do
include "RSpec::Rails::Orm::#{orm.to_s.c
Now with a full RSpec 2 test suite to demonstrate most of its
features. Wiki to be updated with latest changes ASAP.
http://github.com/kristianmandrup/rspec_for_generators
This gem makes it very easy to spec that your generator generates
files as expected and also lets you easily verify that the
r.setup_generator test_method_name, &block
end
end
end
On Aug 7, 4:09 pm, David Chelimsky wrote:
> On Aug 7, 2010, at 8:23 AM, Kristian Mandrup wrote:
>
>
>
> > I simply want all methods of a module to be always available within
> > the context of an Example gr
I simply want all methods of a module to be always available within
the context of an Example group.
module RSpec
module Generator
def with_generator &block
...
end
def setup_generator test_method_name=nil, &block
...
end
end
end
How do I achieve this?
Even simpler config now :)
require 'rspec'
require 'rspec_for_generators'
# configure it like this to use default settings
RSpec::Generator.configure_root_dir(__FILE__)
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/
nd
end
end
end
end
On Aug 4, 5:22 am, David Chelimsky wrote:
> On Aug 3, 2010, at 3:06 PM, Kristian Mandrup wrote:
>
>
>
> >http://github.com/kristianmandrup/rspec_for_generators
>
> > When creating Rails generators I noticed that the only option I could
>
http://github.com/kristianmandrup/rspec_for_generators
When creating Rails generators I noticed that the only option I could
find for testing was to use a special Rails TestCase class created
specifically for use with Test Unit.
So I thought I could wrap it to be used with RSpec 2 instead. I now
h
I have created a complete project where I have extracted all my RSpec
2 utilities, configurations, special matchers etc. for creating nice
Rails 3 Generator specs.
http://github.com/kristianmandrup/rspec_for_generators
An example of use where all specs pass:
http://github.com/kristianmandrup/can
http://github.com/kristianmandrup/canable
In my fork of jnunemaker's canable I show my port of the unit test way
of testing generators for RSpec 2.
It still needs some tidying up to make it even more elegant ;)
Feel free to provide suggestions etc.
Kristian
RSpec 2 example
---
describe 'Generato
http://github.com/kristianmandrup/canable/tree/master/spec/
Example:
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe 'Generator' do
let(:generator) { Rails::Generators::Testcase.new }
with generator do
destination File.join(Rails.root)
tests Canable::Ge
I have been creating a lot of Thor generators and Rails generators
during the past 4 months, but only this week did I find some good
examples of how to write tests for generators using
Rails::Generators::TestCase - in the "rails3-generators" project.
I prefer to write my tests in RSpec 2, so I was
Thanks again David :) Pure magic to me, I don't really understand how/
why that makes it work. But it does!
On Jun 14, 2:30 am, David Chelimsky wrote:
> On Jun 13, 2010, at 5:32 PM, Kristian Mandrup
> wrote:
>
>
>
> > shared_examples_for "a template that render
shared_examples_for "a template that renders the messages/form
partial" do
it "renders the messages/form partial" do
view.should_receive(:_render_partial).
with(hash_including(:partial => "form"))
render
end
end
# new.html.erb
<%= render "sidebar", :recent_messages => @recent_me
Thanks! Just what I needed :)
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
orm", :locals=>{:message=>nil}})
got: ({:template=>"messages/edit.html.erb"}, {})
But this is my edit.html
<%= render "form", :message => @message %>
So _view only contains info on the view. How do I get info on the
templates called as part of the rend
Cause of error:
class Message < ActiveRecord::Base
belongs_to :recipient #, :class_name => User.name
--
it then by convention expects there to be a model class called
Recipient.
should instead be
class Message < ActiveRecord::Base
belongs_to :recipient, :class_name => User.name
But then the
assigns(:message).should eq(@message)
assign(:message, stub("Message", :text => "Hello world!"))
Hmm, so 'assign' to assign a variable and 'assigns' to read an
assigned variable?
We need to update the RSpec 2 wiki or somewhere with all these API
changes so it is clear to everyone.
On Jun 11, 9:
gems/ruby-1.9.2-head/bundler/gems/rspec-
core-2398fcadf5beb256bed9c548c59445d3b4c8a047-master/lib/rspec/core/
backward_compatibility.rb:26:in `const_missing': uninitialized
constant Message::User (NameError)
from /Users/kristianconsult/.rvm/gems/ruby-1.9.2-head/bundler/gems/
rspec-expectati
describe ApplicationController, "handling AccessDenied exceptions" do
class FooController < ApplicationController
def index
raise AccessDenied
end
end
controller_name 'foo' # OUCH!!!
it "redirects to the /401.html (access denied) page" do
get :index
response.should r
describe MessagesController, "POST create" do
before(:each) do
@message = mock_model(Message, :save => nil)
Message.stub(:new).and_return(@message)
end
context "when the message fails to save" do
before(:each) do
@message.stub(:save).and_return(false)
end
it "ass
undefined method `model_name' for Message:Class
---
# spec/views/messages/new.html.erb_spec.rb
class Message; end
describe "messages/new.html.erb" do
it "renders a form to create a message" do
assign(:message, mock_model(Message).as_new_record)
render
# app/views/messages/new
http://github.com/kristianmandrup/codebreaker
With detailed code instructions for each step in the project wiki and
in a markdown file within each app.
http://github.com/kristianmandrup/rspec-book-movie-app
http://github.com/kristianmandrup/rspec-book-views-example
Note: The final example is at
assign(:message, stub("Message"))
In my view I can access the message, but...
<%= @message.to_s %>
expected the following element's content to include "Hello
world!":
#[RSpec::Mocks::Mock:0x81bbd81c @name="Message"]
Finally after some trial and error I discovered the solution, an
option
> assign(:message, stub("Message"))
>
> That should get rid of your deprecation message.
Yeah! But strange deprecation message that it mentions:
* response is deprecated.
* please use rendered instead.
When it should be:
* assigns is deprecated.
* please use assign instead.
Also, how do I use th
I have come to the views_example in the RSpec book, using RSpec 2 all
the way.
Now I have this spec:
--
describe "messages/show.html.erb" do
it "displays the text attribute of the message" do
assigns[:message] = stub("Message", :text => "Hello world!")
puts "assigns @message: #...@message
What are the options for creating specs for file operations, executing
commands in the CLI etc.?
If I build a generator or something which runs a lot of things in the
command line, how do I check the results of these operations, fx
mocking file system updates and/or mocking the STDOUT/STDIN from t
Thanks! I solved it all now and updated the RSpec 2 wiki about how to
set it all up ;)
http://wiki.github.com/rspec/rspec/autotest
Hope these instructions provides a good base and is helpful to others!
___
rspec-users mailing list
rspec-users@rubyforge.
I found the solution here: http://blog.davidchelimsky.net/category/autotest/
--
As of beta.4, you’ll have to do add this configuration manually. Just
create an autotest directory in the root of your project, put the
following statement in ./autotest/discover.rb:
Autotest.add_discovery { "rspec2"
Thanks again David :)
> Don't use RSPEC=true for rspec-2.
>
> Also, probably need to set AUTOFEATURE=false.
>
OK, when I run it like this
$ AUTOFEATURE=false autotest
I get an empty autotest output whenever I change and save a spec.
The above lets me disable features, but how do I ENABLE specs
It seems there is no bin/autospec with RSpec 2. So I got it running
simply with $ autotest
Been looking at instructions here
http://wiki.github.com/dchelimsky/rspec/autotest-integration
And here http://ph7spot.com/musings/getting-started-with-autotest
But...
$ RSPEC=true autotest
loading autot
Thanks ;)
I also tried to follow the instructions on using autospec/autotest,
first from the RSpec book then from instructions found on the net.
I managed to do the following so far:
# config/cucumber.yml
default: --format profile features
html_report: --format progress --format html --
out=feat
Using RSpec 2 beta.
$ rspec spec
* spec/spec.opts is deprecated.
* please use .rspec or ~/.rspec instead.
I tried renaming the file to .rspec but then it has no effect!
# spec/.rspec
--format nested
--color
It works if I copy it to ~/.rspec and it turns out, also if I
copy .rspec to the root o
One hack "solution" looks like this :P
output.messages.include?(mark).should
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
http://pragprog.com/titles/achbd/errata
nr 57:
Ruby 1.8.7
expected [] to include "Welcome to Codebreaker!"
Ruby 1.9.1
undefined method `include' for # (NoMethodError)
---
class Output
def messages
@messages ||= []
end
def puts(message)
messages << message
end
end
Then /^I shoul
# spec_helper.rb
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require '...
require 'rspec'
require 'rspec/autorun'
# doesn't work: just remove it and it works.
# But how would you configure the RSpec Runner in RSpec 2 then?
Rspec::R
I have just finished creating a working set of Rails 3 compatible
generators for RSpec.
http://github.com/kristianmandrup/rspec_rails3_gen
Also available from gemcutter under the same name: rspec_rails3_gen
They work pretty well, except for the hooks functionality which still
needs some work
ho
I have the beta release of the RSpec book. Trying to run the greeting
example 'Hello World'
Using brew as package manager
Installed rspec gem using
$ sudo gem install rspec
kristian-mandrups-macbook-pro:rspec-coding kristianconsult$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3
52 matches
Mail list logo