Sha256: d004bb32864d480dd5234fd2eb388551c27692a143d642043e530b50eb3a62f9

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

require 'test_helper'

class User
  backgrounded :do_stuff

  def do_stuff
  end
end

class Person
  backgrounded :do_stuff

  def do_stuff(name, place, location)
  end
end

class Post
  backgrounded :do_stuff, :notify_users

  def do_stuff
  end
  def notify_users
  end
end

class Comment
  backgrounded :delete_spam!
  
  def delete_spam!
  end
end

class BackgroundedTest < Test::Unit::TestCase
  context 'an object with a single backgrounded method' do
    setup do
      @user = User.new
    end
    should "execute method in background" do
      @user.expects(:do_stuff)
      @user.do_stuff_backgrounded
    end
  end

  context 'an object with a backgrounded method that accepts parameters' do
    setup do
      @person = Person.new
    end
    should 'forward them' do
      @person.expects(:do_stuff).with('ryan', 2, 3)
      @person.do_stuff_backgrounded('ryan', 2, 3)
    end
  end
  
  context 'an object with a backgrounded method included punctuation' do
    setup do
      @comment = Comment.new
    end
    should 'move punctuation to the end of the new method' do
      assert @comment.respond_to?(:'delete_spam_backgrounded!')
    end
  end

  context 'an object with multiple backgrounded methods' do
    setup do
      @post = Post.new
    end
    should "execute method either method in background" do
      @post.expects(:do_stuff)
      @post.do_stuff_backgrounded

      @post.expects(:notify_users)
      @post.notify_users_backgrounded
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
wireframe-backgrounded-0.3.0 test/backgrounded_test.rb
backgrounded-0.4.1 test/backgrounded_test.rb
backgrounded-0.3.1 test/backgrounded_test.rb