testunit

Mocking an external API

亡梦爱人 提交于 2021-01-24 07:08:37
问题 I'm new to testing strategies and mocking, and I'm having a tough time figuring out how to mock a call to an external service. I'm sure it's something easy I'm missing, I just don't know what exactly. I'm using the Braintree gem to charge for subscription services through the Braintree gateway, and I wanted to mock the Customer create method and Subscription create method in my UserController's create method. A Customer.create method looks something like this: result = Braintree::Customer

Mocking an external API

喜欢而已 提交于 2021-01-24 07:05:16
问题 I'm new to testing strategies and mocking, and I'm having a tough time figuring out how to mock a call to an external service. I'm sure it's something easy I'm missing, I just don't know what exactly. I'm using the Braintree gem to charge for subscription services through the Braintree gateway, and I wanted to mock the Customer create method and Subscription create method in my UserController's create method. A Customer.create method looks something like this: result = Braintree::Customer

How to skip certain tests with Test::Unit

对着背影说爱祢 提交于 2020-01-24 02:29:11
问题 In one of my projects I need to collaborate with several backend systems. Some of them somewhat lacks in documentation, and partly therefore I have some test code that interact with some test servers just to see everything works as expected. However, accessing these servers is quite slow, and therefore I do not want to run these tests every time I run my test suite. My question is how to deal with a situation where you want to skip certain tests. Currently I use an environment variable

How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

我是研究僧i 提交于 2020-01-11 14:50:09
问题 I have test-unit installed and rspec installed (along with -core , -expectations , -mocks and -rails version 2.6.x). When I run the command rails new foo , it uses test-unit to generate the test stub files instead of rspec . Is there an option where I can tell rails to use rspec to generate the tests instead? 回答1: The following should work: at command line: rails new MYAPP -T # The -T option tells rails not to include Test::Unit in Gemfile: gem 'rspec-rails' at command line: bundle install

Mongoid not playing nicely with factories

你离开我真会死。 提交于 2020-01-05 04:57:17
问题 Moingoid doesn't seem to be setting embedded relationships persistently during my tests. In my user model I have: def vote_on(bill, value) if my_groups = self.groups my_groups.each do |g| bill.votes.create(:value => value, :user_id => self.id, :group_id => g.id) # result only with factories: bill.votes.first.group = nil # and bill.votes.first.user = nil !! # self.id and g.id have good values during the test, they just aren't persisting end else raise "no groups for this user" # #{self.full

Test unit results in color using console but not tmux unless --use-color is specified

▼魔方 西西 提交于 2019-12-25 05:35:29
问题 If I create a new Rails (3.2.12) app. Add the test-unit gem to my development, test group, and then scaffolded resource. When I run the tests from the Mac console.app, I get color output. bundle exec rake test When I create a tmux session (in console.app) for the app and run the exact same command. I don't get color output. However if I pass the "--use-color" switch, then I do get color output for the tests in tmux. bundle exec rake test TESTOPTS="--use-color" I'm setting 256 colors in my

Test::Unit how to test file operations and file content

最后都变了- 提交于 2019-12-24 20:35:12
问题 I'm looking for a way to test methods that use File class with test_unit. It's really the same thing that issue with Rspec but how to make it work with test_unit. def foo File.open "filename", "w" do |file| file.write("text") end end What will the test be : require 'test/unit' def test_foo ... end Thanks for your help. 回答1: You can do the same thing the RSpec question landed on: have foo accept any IO object and use a StringIO in tests. def foo(io) io.write("text") end Then require "test/unit

What makes a good failure message for testunit or other nunit style frameworks?

倾然丶 夕夏残阳落幕 提交于 2019-12-23 13:16:12
问题 In Ruby's test/unit, and other such nunit style frameworks, what makes a good failure message? Should the failure message merely describe how the expected value does not match the expected value? assert_match("hey", "hey this is a test", "The word does not exist in the string") Should it describe what you expected to happen? assert_match("hey", "hey this is a test", "I expected hey to be in the string") Should it describe why you wanted the behavior to happen? assert_match("hey", "hey this is

How to re-enable Test::Unit in Rails 4 after 'rails new app --skip-test-unit'

我是研究僧i 提交于 2019-12-23 12:32:36
问题 I used rails new app --skip-test-unit because initially, I thought I could add testing later. I developed a significant portion of my app. Now, I would like to add Test::Unit but I couldn't find any documentation on how to do it. Googling only lead me to the Rails Guides and tutorials that assume you didn't ask rails to skip the testing framework when you first created the app. I know I might be able to figure out what _test.rb files to add manually and how to modify the Rakefile (by looking

can't get test unit startup to work in ruby 1.9.2

ぃ、小莉子 提交于 2019-12-21 15:04:08
问题 I am using Ruby 1.9.2 (ruby -v yields :ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]), and I am trying to get this to work: require 'test/unit' class TestStartup < Test::Unit::TestCase def self.startup puts "startup" end def test1 puts "in test1" end end when I run it, I get Loaded suite test_startup Started in test1 . Finished in 0.000395 seconds. 1 tests, 0 assertions, 0 failures, 0 errors, 0 skips I had a hard time finding documentation on this feature, other than scattered