<commit_before># encoding: UTF-8
require_relative "../spec_helper"
require_relative "../promises_aplus"

dummy = { dummy: "dummy" } #  we fulfill or reject with this when we don't intend to test against it
sentinel = { sentinel: "sentinel" } # a sentinel fulfillment value to test for with strict equality

describe "2.2.2: If `onFulfilled` is a function," do
  include PromisesAplus

  describe "2.2.2.1: it must be called after `promise` is fulfilled, with `promise`’s fulfillment value as its first argument." do
    PromisesAplus.test_fulfilled(self, sentinel) do |promise, done|
      promise.then ->(value) {
        value.must_equal sentinel
        done.call
      }
    end
  end

  describe "2.2.2.2: it must not be called before `promise` is fulfilled" do

    it "fulfilled after a delay" do
      d = deferred
      is_fulfilled = false
      d.promise.then ->(v) {
        assert_equal true, is_fulfilled
        done!
      }

      Thread.new do
        short_sleep
        is_fulfilled = true
        d.resolve(dummy)
      end
    end

    it "never fulfilled" do
      d = deferred
      on_fulfilled_called = false

      d.promise.then ->(v) {
        on_fulfilled_called = true
        done!
      }<commit_msg>Added note about deviation from Promises/A+ due to Ruby not having same notion of execution cycles.<commit_after># encoding: UTF-8
require_relative "../spec_helper"
require_relative "../promises_aplus"

dummy = { dummy: "dummy" } #  we fulfill or reject with this when we don't intend to test against it
sentinel = { sentinel: "sentinel" } # a sentinel fulfillment value to test for with strict equality

describe "2.2.2: If `onFulfilled` is a function," do
  include PromisesAplus

  describe "2.2.2.1: it must be called after `promise` is fulfilled, with `promise`’s fulfillment value as its first argument." do
    PromisesAplus.test_fulfilled(self, sentinel) do |promise, done|
      promise.then ->(value) {
        value.must_equal sentinel
        done.call
      }
    end
  end

  describe "2.2.2.2: it must not be called before `promise` is fulfilled" do

    it "fulfilled after a delay" do
      d = deferred
      is_fulfilled = false
      d.promise.then ->(v) {
        assert_equal true, is_fulfilled
        done!
      }

      Thread.new do
        short_sleep
        # Notice: flipped statements since we don't have delayed execution
        is_fulfilled = true
        d.resolve(dummy)
      end
    end

    it "never fulfilled" do
      d = deferred
      on_fulfilled_called = false

      d.promise.then ->(v) {
        on_fulfilled_called = true
        done!
      }
{'fraction_non_alphanumeric': 0.0852683669585078, 'fraction_numerical': 0.009135896459840122, 'mean_word_length': 2.513368983957219, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3725772', 'n_tokens_mistral': 841, 'n_tokens_neox': 792, 'n_words': 278}