These are chat archives for opal/opal

9th
May 2016
Brock Wilcox
@awwaiid
May 09 2016 00:44
@Thermatix ya, what @wied03 said -- https://github.com/seattlerb/minitest#unit-tests is an example of this style
Martin Becker
@Thermatix
May 09 2016 00:47
I actually have a problem against the let or subject mechanism
becuase you can't pass a value into it
you have to do somthing like this:
subject { proc {|input| Differentiator.new(input).result }}
Brock Wilcox
@awwaiid
May 09 2016 00:48
Where does the input come from?
Martin Becker
@Thermatix
May 09 2016 00:48
and then use it like this
subject.([3,2,1]).must_equal "6x+2"
Brock Wilcox
@awwaiid
May 09 2016 00:48
hmm
Martin Becker
@Thermatix
May 09 2016 00:48
it's a proc that returns a proc
so you have to call it
in reality
you should be able to do this:
Brock Wilcox
@awwaiid
May 09 2016 00:49
Interesting. I think I typically just have one subject for a describe block, and maybe have a nested block with an override subject/let if needed
Martin Becker
@Thermatix
May 09 2016 00:49
subject  {|input| Differentiator.new(input).result }
and then use it like this:
subject([3,2,1]).must_equal "6x+2"
basicly I used it for this test data:
describe :test_data do

  # a proc that returns a proc, not how I want it but only way to get this to be dry
  subject { proc {|input| Differentiator.new(input).result }}

  it "expects result to be 6x+2" do
    subject.([3,2,1]).must_equal "6x+2"
  end

  it "expects result to be 12x^2+6x+2" do
    subject.([4,3,2,1]).must_equal "12x^2+6x+2"
  end

  it "expects result to be 12x^2#{-10}x" do
    subject.([4,-5,0,1]).must_equal "12x^2#{-10}x"
  end


end
Brock Wilcox
@awwaiid
May 09 2016 00:50
but subject is, if I understand correctly, basically equivalent to:
before_each do
    @subject = { ... }()
end
hm. I should learn how to use this chat
Austin Erlandson
@erlandsona
May 09 2016 00:50
@Thermatix isn’t that the whole point of “Late binding” though? for example… Usually what I’ll do is define a subject then pass it a let variable that I update in a spec later… EG:
Martin Becker
@Thermatix
May 09 2016 00:51
also junity style <- I don't like this for tests
but it's not very dry
doing it this means you define the code you want to test once
Brock Wilcox
@awwaiid
May 09 2016 00:51
though not quite like a before_each since it is upon the first usage
Martin Becker
@Thermatix
May 09 2016 00:51
and the values that are being used for each test remain inside the blocks for that test
and it's DRY
pass it a let variable?
ah by the way subject is just the same as doing
Brock Wilcox
@awwaiid
May 09 2016 00:53
ya, a let
Martin Becker
@Thermatix
May 09 2016 00:53
let(:subject) { some object stuff}
at least in minitest
it's basically a pre-defined let
Austin Erlandson
@erlandsona
May 09 2016 00:54
describe SomeClass do
  subject { described_class.new(let_variable) }
  let(:let_variable)  { “some initial value” }
  it { is_expected.to be_some_initial_value }

  describe “#method” do
    let(:let_variable) { “some other value” }
    it { is_expected.to be_some_other_value }
  end
end
Martin Becker
@Thermatix
May 09 2016 00:55
I didn't know you could do that
I wonder if that works minitest
Austin Erlandson
@erlandsona
May 09 2016 00:56
Yup. that’s why they’re called late binding. It uses laziness so that the variable doesn’t get set except in the context it’s needed… It’s very Haskell-like.
Martin Becker
@Thermatix
May 09 2016 00:56
I see I see
that's dry and more expressive
I like it
but does it work in minitest?
Austin Erlandson
@erlandsona
May 09 2016 00:58

In case you’re into it betterspecs.org is a great resource for learning how to write better specs… LOL No pun intended but for real I learned a ton about writting good specs from there…

Let me know if it does work in MiniTest because I’m really pissed off trying to get rspec to not run my specs twice when I’ve got them in the app directory.

Any thoughts?

Martin Becker
@Thermatix
May 09 2016 01:01
one moment
it does work
had to add some context's though
describe :test_data do

  subject {Differentiator.new(input).result }

  describe :first_test do
    let(:input){[3,2,1]}
    it "expects result to be 6x+2" do
      subject.must_equal "6x+2"
    end
  end

  describe :second_test do
    let(:input){[4,3,2,1]}
    it "expects result to be 12x^2+6x+2" do
      subject.must_equal "12x^2+6x+2"
    end
  end

  describe :third_test do
    let(:input){[4,-5,0,1]}
    it "expects result to be 12x^2#{-10}x" do
      subject.must_equal "12x^2#{-10}x"
    end
  end

end
Austin Erlandson
@erlandsona
May 09 2016 01:03
Yeauh yeauh!!! Wait, those are MiniTest specs? Dude!!! I’m totally switching! Holy crap! Wait does MiniTest have Shoulda-Matchers?
Martin Becker
@Thermatix
May 09 2016 01:03
yes
no idea
but maybe?
of course shoulda supports “you’re testing framework of choice.” Like most good gems would right?! Wait a second… why on earth am I using Rspec then?
Martin Becker
@Thermatix
May 09 2016 01:05
lol
becuase some one told you
"Evyer oen using rspec"
so you thought
Austin Erlandson
@erlandsona
May 09 2016 01:06
I hate the world right now. Freaking “Rails way” is the most absurd thing I’m coming to realize! Good God Ruby peeps, why?!
Martin Becker
@Thermatix
May 09 2016 01:06
"Ok I'm going to use rspec too, just like every one else"
this is why I like sinatra
YES you have to set it up yourself
but as a result
you know it
inside
and out
I can intergrate sprockets into sinatra now easioly
and with opal
and anything else I might want
I even worked out how to do a rails style separate route to symbol mapper
then you could just reference the symbol in sinatra and it would automatically map to it when you called it
Austin Erlandson
@erlandsona
May 09 2016 01:08
I really want to work on whatever project you’re working on @Thermatix. I need to learns and I feel like even the most Sr. Dev’s at my company can’t answer these questions… Ugh…
Martin Becker
@Thermatix
May 09 2016 01:09
lol that I did for fun
now I have to add spec's to my ruta library before I continue
I want to add some features but with everything added I risk the chance of breaking it
so good test coverages is needed
but at the moment I'm not working on any projects besides personal stuff
out of a job at the moment :(
and almost every company I've interviewed at have cheated me
I'm looking for junior-midlevel
what they want is a midlevel willing to work for the pay of a junior
but they can't say that
so they go
OH you're not senior enough
...
senior enough for a junior-ish role?
really?
but yeah I know how that feels
when I Was at just giving I was the most knowledgeable at ruby
so I had to figure everything out my-self
wasn't easy
but I learnt a lot doing it
but I probably picked up a lot of bad habbits probably
sorry
rambling
Austin Erlandson
@erlandsona
May 09 2016 01:14
Naw I feel the same. Granted I'm very fortunate and great ful for my Salary at the moment. Hoping to get a bit of a raise soon? We'll see.
Martin Becker
@Thermatix
May 09 2016 01:15
good lucj
luck*
Brady Wied
@wied03
May 09 2016 16:05
@erlandsona - I think it's bless black and white than that re: the Rails way
and sometimes the quest for simplicity can be as blinding as the Rails colored glasses
Austin Erlandson
@erlandsona
May 09 2016 16:23
Fair enough @wied03 agreed.
Jamie Gaskins
@jgaskins
May 09 2016 22:03
@wied03 And not even everyone defines simplicity the same. Some think less code is simpler. Some think less magic is simpler. :-)
Austin Erlandson
@erlandsona
May 09 2016 22:36
Truths
Mitch VanDuyn
@catmando
May 09 2016 23:07
@/all setting up a small gem that has some configuration that is needed on both the server and client...
what is the best approach for doing this.
say for example I have a config variable Foo.key that is set in an initializer on the server...
I want the same value of key to be accessible on the client.
If I was sure I was in rails I would so a <%= Foo.key %> but not sure if that is guaranteed to work in all situations?