Skip to content
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.

clean up syntax #15

Open
catmando opened this issue May 22, 2018 · 0 comments
Open

clean up syntax #15

catmando opened this issue May 22, 2018 · 0 comments

Comments

@catmando
Copy link
Contributor

right now we say:

  evaluate_ruby { ... }  # evaluates block and returns result
  expect_evaluate_ruby { ... }.to be >= 12 # runs block on client and then checks result
  expect_promise { ... }.to be >= 12 # runs block on client, and waits for the promise to resolve

evaluate_ruby should become on_client, shorter and clearer.

Given this should

expect_evaluate_ruby become expect_on_client and
expect_promise stays as is
or
expect { ... }.on_client and
expect { ... }.promises ??

some examples:

require "spec_helper"

RSpec::Steps.steps "Element#css", js: true do

  before(:step) do
    insert_html <<-HTML
      <div id="foo" style="background-color:rgb(15,99,30); color:;"></div>
      <div id="bar"></div>
      <div id="hash"></div>
      <div id="animate-foo"></div>
      <div id="effects-foo"></div>
    HTML
  end

  it "with a given name: returns the value of the CSS property for the given name" do
    expect do
      Element.find('#foo').css('backgroundColor')
    end.on_client.to eq('rgb(15, 99, 30)')
  end

  # it "with a given name: should return an empty string when no style property is defined for name"
  # the above is not true (at least not any more).   All css properties that I know of have a defined
  # default value.  I.e. no color = rgb(0,0,0)

  it "with a name and value: should set the CSS property to the given value" do
    on_client do
      Element.find('#bar').css('backgroundColor', 'blue')
    end
    expect(find('#bar', visible: false).native.css_value('background-color')).to eq('rgba(0, 0, 255, 1)')
  end

  it "with a name and value: returns self" do
    expect do
      bar = Element.find('#bar')
      bar.css("background", "green") == bar
    end.on_client.to be_truthy
  end

  it "with a set of names and values: should set the properties" do
    on_client do
      hash = Element.find("#hash")
      hash.css(:width => "100px", :height => "200px")
    end
    expect(find('#hash', visible: false).native.css_value('width')).to eq('100px')
    expect(find('#hash', visible: false).native.css_value('height')).to eq('200px')
  end

  it "with a set of names and values: should return self" do
    expect do
      hash = Element.find("#hash")
      hash.css(:border => "1px solid #000") == hash
    end.on_client.to be_truthy
  end

  it "animation should accept a block as a callback" do
    on_client do
      start_time = Time.now
      foo = find('#animate-foo')
      foo.animate :width => "200px" do
        @animated.resolve! Time.now - start_time
      end
    end
    expect_promise { @animated = Promise.new }.to be >= 0.4
  end

end

or

require "spec_helper"

RSpec::Steps.steps "Element#css", js: true do

  before(:step) do
    insert_html <<-HTML
      <div id="foo" style="background-color:rgb(15,99,30); color:;"></div>
      <div id="bar"></div>
      <div id="hash"></div>
      <div id="animate-foo"></div>
      <div id="effects-foo"></div>
    HTML
  end

  it "with a given name: returns the value of the CSS property for the given name" do
    expect_on_client do
      Element.find('#foo').css('backgroundColor')
    end.to eq('rgb(15, 99, 30)')
  end

  # it "with a given name: should return an empty string when no style property is defined for name"
  # the above is not true (at least not any more).   All css properties that I know of have a defined
  # default value.  I.e. no color = rgb(0,0,0)

  it "with a name and value: should set the CSS property to the given value" do
    on_client do
      Element.find('#bar').css('backgroundColor', 'blue')
    end
    expect(find('#bar', visible: false).native.css_value('background-color')).to eq('rgba(0, 0, 255, 1)')
  end

  it "with a name and value: returns self" do
    expect_on_client do
      bar = Element.find('#bar')
      bar.css("background", "green") == bar
    end.to be_truthy
  end

  it "with a set of names and values: should set the properties" do
    on_client do
      hash = Element.find("#hash")
      hash.css(:width => "100px", :height => "200px")
    end
    expect(find('#hash', visible: false).native.css_value('width')).to eq('100px')
    expect(find('#hash', visible: false).native.css_value('height')).to eq('200px')
  end

  it "with a set of names and values: should return self" do
    expect_on_client do
      hash = Element.find("#hash")
      hash.css(:border => "1px solid #000") == hash
    end.to be_truthy
  end

  it "animation should accept a block as a callback" do
    on_client do
      start_time = Time.now
      foo = find('#animate-foo')
      foo.animate :width => "200px" do
        @animated.resolve! Time.now - start_time
      end
    end
    expect { @animated = Promise.new }.promises.to be >= 0.4
  end
end
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant