"
end
end
context "The SomeHelper"
helper_name :some
specify do
some_helper_method.should have_tag("p", "foo")
end
end
Til
ps: the new have_tag / with_tag stuff for testing views and rspec
0.8.2 in general rocks, thanks to all involved!
From dchelimsky at gmail.com Fri Mar 9 11:10:39 2007
From: dchelimsky at gmail.com (David Chelimsky)
Date: Fri, 9 Mar 2007 10:10:39 -0600
Subject: [rspec-users] AssertSelect for strings?
In-Reply-To: <20070309150350.GA30865@tils.net>
References: <20070309150350.GA30865@tils.net>
Message-ID: <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com>
That's a great idea, but AFAIK it is not supported by assert_select directly.
Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb.
This is a copy of the assert_select_test from the
assert_select_plugin, modified to fit into rspec.
It sets up a controller that you can use to render whatever text you
like, and set up specs like this:
render_html %Q{

foo

}
response.should have_tag('p','foo')
There's no reason you shouldn't be able to do this:
render_html(some_helper_method)
response.should have_tag('p','foo')
It's a bit sneaky, and perhaps too much work when you could just do:
some_helper_method.should == "

foo

"
Check it out and let me know if you have any questions.
Cheers,
David
On 3/9/07, Tilmann Singer wrote:
> Hi,
>
> Is there a way to use the have_tag matcher on a string instead of the
> response body from a view? I have a helper in a method rails project
> that returns an html fragment which I would like to test.
>
> Like this:
>
> module SomeHelper
> def some_helper_method
> "

foo

"
> end
> end
>
> context "The SomeHelper"
> helper_name :some
> specify do
> some_helper_method.should have_tag("p", "foo")
> end
> end
>
>
>
> Til
>
>
> ps: the new have_tag / with_tag stuff for testing views and rspec
> 0.8.2 in general rocks, thanks to all involved!
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From dchelimsky at gmail.com Fri Mar 9 11:11:31 2007
From: dchelimsky at gmail.com (David Chelimsky)
Date: Fri, 9 Mar 2007 10:11:31 -0600
Subject: [rspec-users] AssertSelect for strings?
In-Reply-To: <20070309150350.GA30865@tils.net>
References: <20070309150350.GA30865@tils.net>
Message-ID: <57c63afe0703090811jffbf090nd8324bc25fc9bce6@mail.gmail.com>
On 3/9/07, Tilmann Singer wrote:
> ps: the new have_tag / with_tag stuff for testing views and rspec
> 0.8.2 in general rocks, thanks to all involved!
You're welcome. Thanks for saying so.
Cheers,
David
From tils-rspec at tils.net Fri Mar 9 13:40:19 2007
From: tils-rspec at tils.net (Tilmann Singer)
Date: Fri, 9 Mar 2007 19:40:19 +0100
Subject: [rspec-users] AssertSelect for strings?
In-Reply-To: <57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com>
References: <20070309150350.GA30865@tils.net>
<57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com>
Message-ID: <20070309184019.GB30865@tils.net>
* David Chelimsky [20070309 17:13]:
> That's a great idea, but AFAIK it is not supported by assert_select directly.
>
> Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb.
> This is a copy of the assert_select_test from the
> assert_select_plugin, modified to fit into rspec.
>
> It sets up a controller that you can use to render whatever text you
> like, and set up specs like this:
This sets up a context for spec'ing controllers with :context_type =>
:controller. As far as I understand it I cannot use that when I want
to test it from within a helper context, and I don't know how to set
up a controller inside a helper context (and if it would be feasible).
I think you can pass a HTML::Node to assert_select somehow, so maybe
there is a way, but so far I didn't find it.
> It's a bit sneaky, and perhaps too much work when you could just do:
>
> some_helper_method.should == "

foo

"
True.
The actual reason why I want to do it is because the helper returns a
string that can contain a link which I want to test
independently. Here is a less contrived example:
module SomeHelper
def some_helper_method
"

"
end
end
context "The SomeHelper"
helper_name :some
specify "should return a sentence" do
some_helper_method.should have_tag("p", "This sentence contains a link.")
end
specify "should include a link" do
some_helper_method.should have_tag("a", "link")
end
end
It's not too bad to workaround with regexps somehow like this:
context "The SomeHelper"
helper_name :some
specify "should return a sentence" do
some_helper_method.should match(/This sentence contains a.*link.*\./)
end
specify "should include a link" do
some_helper_method.should match(%r{link})
end
end
but using the assert_select syntax would be much more elegant.
Til
From dchelimsky at gmail.com Fri Mar 9 15:42:24 2007
From: dchelimsky at gmail.com (David Chelimsky)
Date: Fri, 9 Mar 2007 14:42:24 -0600
Subject: [rspec-users] AssertSelect for strings?
In-Reply-To: <20070309184019.GB30865@tils.net>
References: <20070309150350.GA30865@tils.net>
<57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com>
<20070309184019.GB30865@tils.net>
Message-ID: <57c63afe0703091242q1d4b35d9sbc8e0494bdbd2cc9@mail.gmail.com>
On 3/9/07, Tilmann Singer wrote:
> * David Chelimsky [20070309 17:13]:
> > That's a great idea, but AFAIK it is not supported by assert_select directly.
> >
> > Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb.
> > This is a copy of the assert_select_test from the
> > assert_select_plugin, modified to fit into rspec.
> >
> > It sets up a controller that you can use to render whatever text you
> > like, and set up specs like this:
>
> This sets up a context for spec'ing controllers with :context_type =>
> :controller. As far as I understand it I cannot use that when I want
> to test it from within a helper context, and I don't know how to set
> up a controller inside a helper context (and if it would be feasible).
>
> I think you can pass a HTML::Node to assert_select somehow, so maybe
> there is a way, but so far I didn't find it.
>
> > It's a bit sneaky, and perhaps too much work when you could just do:
> >
> > some_helper_method.should == "

foo

"
>
> True.
>
> The actual reason why I want to do it is because the helper returns a
> string that can contain a link which I want to test
> independently. Here is a less contrived example:
>
> module SomeHelper
> def some_helper_method
> "

"
> end
> end
>
> context "The SomeHelper"
> helper_name :some
> specify "should return a sentence" do
> some_helper_method.should have_tag("p", "This sentence contains a link.")
> end
>
> specify "should include a link" do
> some_helper_method.should have_tag("a", "link")
> end
> end
>
>
> It's not too bad to workaround with regexps somehow like this:
>
> context "The SomeHelper"
> helper_name :some
> specify "should return a sentence" do
> some_helper_method.should match(/This sentence contains a.*link.*\./)
> end
>
> specify "should include a link" do
> some_helper_method.should match(%r{link})
> end
> end
>
>
> but using the assert_select syntax would be much more elegant.
Agreed. I'd recommend you post a request to both rspec for have_tag
and to rails for assert_select.
>
>
> Til
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
From cwdinfo at gmail.com Fri Mar 9 16:40:00 2007
From: cwdinfo at gmail.com (s.ross)
Date: Fri, 9 Mar 2007 13:40:00 -0800
Subject: [rspec-users] Mocks & Stubs in spec_helper?
Message-ID: <2DC48A38-6CCE-455C-BCAD-DFD6A8866FC9@gmail.com>
I have to stub out
setup do
request.stub!(:user_agent).and_return('Mozilla')
end
in each context because my Rails application.rb relies on it (for IE
reasons).
Is there a way to create mocks or stubs in spec_helper.rb so I don't
have to repeat this?
Thanks,
Steve
From dchelimsky at gmail.com Sat Mar 10 08:56:37 2007
From: dchelimsky at gmail.com (David Chelimsky)
Date: Sat, 10 Mar 2007 07:56:37 -0600
Subject: [rspec-users] AssertSelect for strings?
In-Reply-To: <57c63afe0703091242q1d4b35d9sbc8e0494bdbd2cc9@mail.gmail.com>
References: <20070309150350.GA30865@tils.net>
<57c63afe0703090810l34689462lc4257d66ea4b31a2@mail.gmail.com>
<20070309184019.GB30865@tils.net>
<57c63afe0703091242q1d4b35d9sbc8e0494bdbd2cc9@mail.gmail.com>
Message-ID: <57c63afe0703100556l68ef34eey3e26b2bc70f6ad2e@mail.gmail.com>
On 3/9/07, David Chelimsky wrote:
> On 3/9/07, Tilmann Singer wrote:
> > * David Chelimsky [20070309 17:13]:
> > > That's a great idea, but AFAIK it is not supported by assert_select directly.
> > >
> > > Take a look at vendor/plugins/rspec_on_rails/spec/rails/matchers/assert_select_spec.rb.
> > > This is a copy of the assert_select_test from the
> > > assert_select_plugin, modified to fit into rspec.
> > >
> > > It sets up a controller that you can use to render whatever text you
> > > like, and set up specs like this:
> >
> > This sets up a context for spec'ing controllers with :context_type =>
> > :controller. As far as I understand it I cannot use that when I want
> > to test it from within a helper context, and I don't know how to set
> > up a controller inside a helper context (and if it would be feasible).
> >
> > I think you can pass a HTML::Node to assert_select somehow, so maybe
> > there is a way, but so far I didn't find it.
> >
> > > It's a bit sneaky, and perhaps too much work when you could just do:
> > >
> > > some_helper_method.should == "

foo

"
> >
> > True.
> >
> > The actual reason why I want to do it is because the helper returns a
> > string that can contain a link which I want to test
> > independently. Here is a less contrived example:
> >
> > module SomeHelper
> > def some_helper_method
> > "