jimweirich / flexmock Goto Github PK
View Code? Open in Web Editor NEWFlexible mocking for Ruby testing
Home Page: http://flexmock.rubyforge.org/
Flexible mocking for Ruby testing
Home Page: http://flexmock.rubyforge.org/
tags.rake
file has shebang (#!/usr/bin/env ruby
).
If we would run like this ./tags.rake
, the shebang is needed.
However if not, it might be better that the lines are removed.
After checking other *.rake files, I did not see shebang for the files.
https://github.com/jimweirich/flexmock/blob/master/rakelib/tags.rake#L1-L2
#!/usr/bin/env ruby
# -*- ruby -*-
Can you remove the lines?
Because I saw the warning message for flexmock
RPM file on Fedora Project.
Thanks.
I've found that new Rubies do not really love Object#methods(false) - it's not documented anymore, and delegates explode with it. Delegates that means also tempfiles and all the rest of the affair - which is actually pretty broken. Why don'y we replace it with singleton_methods? This gets rid of the problem.
I've filed an issue with ruby-core on delegates
http://redmine.ruby-lang.org/issues/4882
but in the meantime I've prepared a handy commit for you here
julik@4acea00
Here's what happens because of this problem:
singleton?' /Users/julik/.rvm/gems/ruby-1.9.2-p180/gems/flexmock-0.9.0/lib/flexmock/partial_mock.rb:236:in
stow_existing_definition'add_mock_method' /Users/julik/.rvm/gems/ruby-1.9.2-p180/gems/flexmock-0.9.0/lib/flexmock/partial_mock.rb:46:in
initialize'Also, please be so kind to either fix your bug report form or disable the Issues tab here. Or both. Or disable the form and enable Issues. Or neither. Dunno.
http://www.picupine.com/629b3b8x
Running
gem 'minitest'
require 'minitest/autorun'
require 'flexmock'
class TestMergeCommand <Minitest::Test
include FlexMock::TestCase
def test_execute
app = flexmock('app')
app.should_receive(:dummy).once
@model = Array.new
assert_nil(@model.index(app))
end
end
gives
Run options: --seed 27174
Running:
E
Finished in 0.001054s, 949.1800 runs/s, 949.1800 assertions/s.
- Error:
TestMyClass#test_my_class:
NoMethodError: undefined methodassertions' for #<FlexMock::TestUnitFrameworkAdapter:0x000000013ea4d0> test/pry_test.rb:28:in
test_my_class'
1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
Tested with
I am receiving the following error:
NoMethodError: undefined method `assertions' for #<FlexMock::TestUnitFrameworkAdapter:0x007fc7bd70c470>
When I try to run the following test:
basket_mock = flexmock(@basket).should_receive(:discount_instance)
.with("promo")
.and_return(promo_mock)
On the code:
def discount_from_codes(*types)
return types.inject(0) do |result, element|
if discount_instance(element)
math = discount_instance(element).discount_for_basket(self)
end
result + math.to_f
end
end
When I change the variable to me "promo" it seems to run through correctly - is there an issue when trying to use flexmock with variable arguments as opposed to string arguments?
In MiniTest 2.12.0, assert_block was deprecated. Any expectation failure results in a deprecation warning coming from the super send at test_unit_integration.rb:53
.
I had a brief look at how to fix it, but I wasn't sure of the best way to proceed. It would be possible to replace the implementation of TestFrameworkAdapter#assert_block
with something like this:
assert(yield, message)
But I'm not sure if that provides the desired error message or not.
I'd be happy to work on a pull request given a little direction of the best approach to take.
Right now I am seeing flexmock
's license is copy right.
However is it possible to decide your license type for that, and add the license file such as LICENSE.txt
?
Because there are flexmock
RPM package in Fedora project.
And I am going to contribute to flexmock
's RPM package.
https://admin.fedoraproject.org/pkgdb/package/rpms/rubygem-flexmock/
It might be better for us to have license file.
Github also supporting license file.
Popular license is MIT
in rubygem packages.
You might be able to add it easily from github web site.
https://help.github.com/articles/licensing-a-repository/
As this repo is not repo for https://rubygems.org/gems/flexmock any more,
I want you to change the description of this repo to link to correct one: https://github.com/doudou/flexmock
Because of preventing people's confusion.
I tried to report this issue on http://onestepback.org/cgi-bin/bugs.cgi?project=flexmock but i can't get passed the 'Please supply a detailed description of the bug report.' guard, so I'll try it here again:
When I mock a method that is created on the fly via method_missing
and known to respond_to?
because of the usage of respond_to_missing?
(which got introduced with ruby 1.9) flexmock throws a NameError
in the teardown once it is trying to realias the original methods. lib/flexmock/partial_mock.rb:280:in 'alias_method'
I changed your 'Creating Partial Mocks' example a bit, to show the exact error and the 'workaround' I came up with: https://gist.github.com/2368754
Using the "have_failed" matcher with flexmock invokes an RSpec warning. For example, the following spec:
require 'rspec/given'
require 'flexmock/rspec/configure'
class Dog
def initialize(tail)
@tail = tail
end
def happy
end
end
describe Dog do
Given(:tail) { flexmock() }
Given(:fido) { Dog.new(tail) }
When { fido.happy }
Then { tail.should have_received(:wag).once }
end
gives the following output:
F
Failures:
1) Dog should When you call a matcher in an example without a String, like this:
specify { object.should matcher }
or this:
it { should matcher }
RSpec expects the matcher to have a #description method. You should either
add a String to the example this matcher is being used in, or give it a
description method. Then you won't have to suffer this lengthy warning again.
Failure/Error: Then { tail.should have_received(:wag).once }
expected wag(...) to be received by <FlexMock:unknown> once.
No messages have been received
# /Users/jim/pgm/ruby/testexample/missing_description_spec.rb:16:in `block (2 levels) in <top (required)>'
# /Users/jim/pgm/ruby/testexample/missing_description_spec.rb:16:in `block in Then'
Finished in 0.00042 seconds
1 example, 1 failure
I installed Flexmock 0.8.11 and got the error
partial_mock.rb:94: syntax error, unexpected ',', expecting '|' (SyntaxError)
define_method(method_name) { |*args, &block|
when trying to start up my server (See Full Stack Trace Below.) I am using Ruby 1.8.6. I suspected the syntax error might be a difference between 1.8 and 1.9. So I installed and tried it with Ruby 1.9.1 and the server started up OK.
If there's an (easy) way to get it to work with Ruby 1.8 and 1.9, cool. If not, then I'd just change your README.rdoc to specify that Ruby 1.9.x or greater is required for this version of Flexmock, because currently it says 1.8.x is OK.
(Note, I downgraded my flexmock to 0.8.6 and that works for now. I don't know where the cutoff line for the Ruby 1.8 vs. 1.9 requirement between Flexmock 0.8.6 and 0.8.11. I didn't try once I got something working again :)
FULL STACK TRACE HERE:
c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in require': C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.1 1/lib/flexmock/partial_mock.rb:94: syntax error, unexpected ',', expecting '|' (SyntaxError) define_method(method_name) { |*args, &block| ^ C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock/partial_mock.rb:101: syntax error, unexpected '}', expecting kEND C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock/partial_mock.rb:295: syntax error, unexpected $end, expecting kEND from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in
require'
from C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock/base.rb:22
from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in require' from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in
require'
from C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock.rb:12
from C:/Ruby/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in require' from C:/Ruby/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in
require'
from C:/Ruby/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:62:in each' ... 12 levels... from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:182:in
require'
from c:/workspace/proctor_dev/vendor/rails/railties/lib/commands/server.rb:84
from script/server:3:in `require'
from script/server:3
I would expect to be able to define a partial mock (i.e. flexmock(realobject)
), use the object and then test against what messages were sent to the real object. Here's an example of what I mean using a flexmock on a class:
require 'spec_helper'
class Foo
class << self
attr_accessor :track_this_value
end
end
describe "spying and passing through" do
before { flexmock(Foo) }
subject { Foo }
before { Foo.track_this_value = "baz" }
its(:track_this_value) { should == "baz" } # it passes through
it "records methods on the mocked class" do
Foo.should have_received(:track_this_value)
end
end
The test does pass the its(:track_this_value)
expectation, but not the should have_received
. Instead I get:
1) spying and passing through records methods on the mocked class
Failure/Error: Foo.should have_received(:track_this_value)
expected track_this_value(...) to be received by Foo.
No messages have been received
# ./spec/spy_spec.rb:16:in `block (2 levels) in <top (required)>'
a = flexmock 'a'
a.should_receive(:foo).with(1).ordered
a.should_receive(:foo).with(2).ordered
a.should_receive(:foo).with(1).ordered
a.foo 1
a.foo 2
a.foo 1
Will fail (@1.3.3). Is it supposed to?
I am currently working around this using the should_expect syntax.
Cheers, Severin
First the error message ... which looks weird. It basically both says that a method has not been called, but this method signature can be found in the message list:
test_data_reader_creates_reader_on_associated_port(TC_RobyPlugin_TaskContext) [/home/doudou/dev/virgo/.gems/gems/flexmock-1.0.3/lib/flexmock/validators.rb:48]:
in mock 'mock for #Orocos::Spec::OutputPort:0x00000004196eb0': Method 'reader({:pull=>true, :type=>:buffer, :size=>20})' called incorrect number of times
1 call expected
0 matching calls found
The following messages have been received:
to_ary()
reader({:pull=>true, :type=>:buffer, :size=>20})
I set up two expectations on reader:
The first one is a catch-all
task.orogen_task.port("out").should_receive(:reader)
The second one is more specific
task.orogen_task.port("out").should_receive(:reader).with({:pull => true, :type => :buffer, :size => 20}).once
If I comment the first one, the error is reported. Otherwise, the test passes fine.
require "minitest/autorun"
require 'flexmock/test_unit'
class SimpleTest < MiniTest::Unit::TestCase
def test_flexmock
flexmock()
end
end
results in the following:
undefined method `teardown' for class `Test::Unit::TestCase' (NameError)
from D:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/flexmock-1.3.1/lib/flexmock/test_unit.rb:16:in `<module:Unit>'
This is the case for ruby1.9.3 and ruby2.0.0 with minitest 4.1.0
Hi,
Seems like 02c927c disables :allocate for 1.9 ruby for .0.9 version. What's the underlying reason?
I'm working on migrating an existing 1.8 codebase to 1.9 and I don't think mocking :new is sufficient to get the tests working.
Running flexmock 1.3.2 & Minitest 5.0.6
require 'minitest/autorun'
require 'flexmock/unit_test'
class TestFlexMock < Minitest::Test
def test_this
flexmock()
end
end
results in
TestFlexMock#test_this:
NoMethodError: undefined method `flexmock' for #<TestFlexMock:0x00000101253c60>
blah.rb:8:in `test_this'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.