Displaying 20 results from an estimated 3000 matches similar to: "stubs which yield and return"
2006 Jun 28
2
[PATCH] Bug fixes and additions to scoped_access
I found that scoped_access does not re-evaluate the filters on every
run. If you are filtering access based on parameters, this can be bad.
The scope is set on the first request and then further requests use the
last generated scoping.
The initial part of ScopedAccess::Filter#before looks like this:
@scoping = controller.instance_eval(@scoping.to_s) if
@scoping.is_a?(Symbol)
This makes
2007 Aug 08
5
and_yield + instance_eval(&block)
I have the following code, which yields instance eval''s the block given:
class Foo
def bar(&blk)
instance_eval &blk
end
def baz
yield
end
end
The effect of this is that self is reassigned:
Foo.new.bar do
# here, self is the instance of Foo
# created by new
end
But normally self is the object in which
Foo.new.bar {...} occurs.
Foo.new.baz do
2007 Aug 14
4
(no subject)
How would you spec out something like the following:
def a_method
x = Class.new do
include Enumerable
end
# do something here with x
end
describe "The Anonymous Class" do
before :each do
@anonymous_class = mock Class
Class.stub!(:new).and_return @anonymous_class
end
it "should create a new anonymous class" do
2008 Jan 23
6
sharing specs in a subclass
Hi
I''ve spec''d a class and they pass.
Now I''d like to assure that any subclass of this class also passes
the same specs.
Any suggestions for a clever way to handle this?
I''d prefer to keep the existing specs as is (eg instead of moving
everything into shared behaviors, or doing something to all the
''describe'' lines)
thanks
linoj
2008 Jul 25
21
Problems with mock assigned to a constant
Hi all,
Initially I thought this was a bug in the built-in mocking framework(and it
still may be), but I better hash it out on the mailing list before I
file/reopen the ticket:
http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6
I thought my example illustrated my problem, but obviously I was passing the
wrong arguments to the mock. I revised my example to
2007 Sep 21
3
TextMate Bundle and exception when switching to alternate file.
Hey,
sorry if this is something better suited to another list.
I''ve encountered a strange problem with the RSpec.tmbundle in trunk -
namely that it was raising an exception when pressing
ctrl-shift-downarrow (switch between spec and source - "Alternate
File").
I tracked down the issue to be handling of the file_type in
switch_command.rb#content_for() - the code expected the
2007 Mar 30
7
problem with using any_instance
Hey all,
I have a question with using mocha in my tests.
In the same test file, I have two tests,
<code>
def test_a
klass.any_instance.stubs(:method_name).returns("something")
klass.new.method_name
...
end
def test_b
...
klass.new.method_name
...
end
</code>
where klass is some class
when the tests run, test _a passes, but test_b had an error like this:
2006 Feb 01
7
Explanation of "alias_method"
Hi!
I''m trying to extend ActiveRecord''s find method (Rails 1.0, Ruby 1.8.2),
but I recognize a strange behaviour of the "alias_method" call.
I wrote a very simple script to explain my problem:
------------------------------------------------------
module ActiveRecordExtension
def self.included(base)
base.extend(ClassMethods)
base.class_eval do
2006 Feb 07
4
Ruby, Rails & Inheritance
Hi!
I am looking for a solution for the following problem:
Some of my models share some attributes and also was in need for some
extra features, so I created a class "RecordWithFeatures":
-----------------------------------------------------------------
class RecordWithFeatures < ActiveRecord::Base
# @Override
def self.descends_from_active_record?
superclass ==
2007 Mar 24
15
State Based vs. Behaviour Based Spec/Testing
I''ve notice that a project like Rubinius has both a spec & a test
directory. Rspec has only a spec directory. Obviously I support
BDD, but isn''t there also a place for state based/verification
testing? I sometimes sense that I *do* want to practice Test Driven
Development. That is, I want some assurance that my production code
will run as intended. But I also
2007 Jun 21
3
Sqlite3, in-memory db and rspec_server
Hi everyone.
I can''t get the above(subject line) combination to work. If I use a
standard sqlite3 file db for the test db, and spec_server all the
specs on my models pass. If I use an in-memory db for the test db,
script/spec w/o spec_server, they all pass. But if I use in-memory and
spec_server I get the following error:
1)
ActiveRecord::StatementInvalid in ''User should be
2007 Apr 20
5
stubbing with and without a string
What is the difference between these two ways of mocking (with and
without the string):
mock(''Object'')
and
mock(Object)
?
Scott
2009 Nov 26
4
Is this a bug?
Hello all, while I''m using acts_as_audited(on jruby platform),
after vendored the acts_as_audited, it reports some error,
line 167,
# Start observing the declared classes and their subclasses.
def initialize
Set.new(observed_classes + observed_subclasses).each { |klass|
add_observer! klass } #this line
end
after some trace shows this one, when observed_classes is empty, will
2006 Mar 27
2
:through and STI
Hi,
I''m trying to use :through and STI using the trunk version of Rails, but
I get the following error see bottom of this msg[1]
here are my classes.
class Player < ActiveRecord::Base
end
class Ladder < ActiveRecord::Base
has_many :subscriptions
has_many :players, :through => :subscriptions
end
class SingleLadder < Ladder
end
class Subscription <
2005 Dec 15
1
Ruby Hash wierdness
Hi
I''m having problems with using a hash. I put in a class and when I
retrieve it, it''s automagically become a string
ie
<%= button_link _("Export CSV"),
SearchParams.get_url_hash({ :action => :export_csv, :klass =>
Customer }, params, @search_fields) %>
Customer is a class that is available to my view
def export_csv
klass =
2006 Jun 26
1
ActiveRecord, instance_eval, and PStore
I''m trying to add some per-object behaviors to objects descended from
ActiveRecord, by using after_initialize() and instance_eval(), like this:
def after_initialize
self.instance_eval(File.read(''customers/default.rb''))
end
(Ultimately the file path will be dynamic, this is just proof of concept.)
default.rb just contains a few method definitions like this one:
def
2007 Sep 05
6
Caveman Questions
Hello!
I''m just a caveman with some caveman questions.
I''ve been parsing Rspec for quite a while, and I''m writing my first series
of specs. My initial impressions are "Verbose, but understandable. Helpful
and intuitive, but so much to digest." I want to congratulate the folks who
are dedicating a chunk of their lives to writing this, and ask 2 caveman
2007 Aug 14
4
Stubbing all methods
Mocha''s mock/stub framework has the ability to stub all methods on a
mock given. Does RSpec''s mocking framework have this ability? And
if not, is there some reason it shouldn''t be implemeneted?
Regards,
Scott
2006 Feb 10
1
instance_eval and Proc objects
Hi All,
Got a bit of a Ruby question for you.
If I have a function that makes a proc object like this:
def select(selector, &proc)
el = Element.new
el.instance_eval proc
end
select("#thing") do
hide
end
Wat I want to do is evaluate the Proc in the context of el but this
doesn''t work because instance_eval accepts a string or a block and not
a Proc object. I sense
2006 Jun 27
3
Weird ActiveRecord Foreign Key Problem
Hello to all,
I ran into a weird problem with an ActivRecord. I have a table named
"build_order" with a column named "type" that is a foreign key to a
table called "building_type". In a controller I try to read all the
build_orders with "BuildOrder.find :all" and get the following error and
stack trace:
(eval):1:in `instance_eval'': compile