Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs #195

Merged
merged 26 commits into from Sep 7, 2015
Merged

Docs #195

merged 26 commits into from Sep 7, 2015

Conversation

waterlink
Copy link
Collaborator

refs #189

This PR adds proper aruba/cucumber/relish setup for alive documentation through BDD.

  • few documented pages.

@egonSchiele you probably need access to those publishers I have created on relish:

For that, can you signup (if you haven't already) on https://relishapp.com/ and send me your relish username (here or by email)?

Relish was chosen because of impression created by rspec's team documentation there. It really looks good and offers nice features.

This PR does not add all the documentation yet, but it would be nice to get this reviewed, code-review-fixed and merged, so that we can go in small increments with this.

How it would look when released can be seen at https://relishapp.com/contracts-staging and https://relishapp.com/contracts-staging/contracts-ruby

Cheers!

@waterlink
Copy link
Collaborator Author

PR is quite big. Might make more sense to review it by one commit at a time.

@egonSchiele
Copy link
Owner

Thanks for doing this @waterlink ! I'll make an account and take a look soon.

@egonSchiele
Copy link
Owner

@waterlink my username is adit.

@waterlink
Copy link
Collaborator Author

I have added you to these publishers. You should be able to see them at your dashboard at https://relishapp.com/my/publishers

@waterlink
Copy link
Collaborator Author

BTW, @egonSchiele Can you take a look at a PR, and how it looks on staging publisher? It is important to merge that, because after that multiple small documentation changes can be done in parallel in their respective *.feature files, even by multiple contributors! - which is awesome :)

Anybody else wants to review? /cc @sfcgeorge @nixpulvis

@waterlink
Copy link
Collaborator Author

Don't be afraid of +1537, -0. It is documentation - pure markdown text and a bit of code examples (not spaghetti code that needs to be understood :D )

@waterlink
Copy link
Collaborator Author

/cc @dg-ratiodata You might want to take a look as well and tell if I have utilized aruba correctly in your opinion.


class << self
Contract C::Num => String
def th(number)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a less complicated function, or just remove this one...two examples is enough.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess you want the third example as the singleton example. Maybe def increment(x); x + 1; end ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change it now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added commit on top of master: 51cfe7c

egonSchiele added a commit that referenced this pull request Sep 7, 2015
@egonSchiele egonSchiele merged commit d03e292 into egonSchiele:master Sep 7, 2015
@egonSchiele
Copy link
Owner

This is really cool @waterlink, thanks for doing it.

You can use `functype(name)` method for that:

```ruby
functype(:add) # => "add :: Num, Num => Num"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really something "normal" end users are going to use? Otherwise I would move that to "features/developers/..." or something similar.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to move it to features/developers/functype.feature I think.

@ghost
Copy link

ghost commented Sep 7, 2015

@waterlink I think you're on a very good way. :-)

What I found out while "writing" our documentation:

  1. Concentrate on API which is relevant to your users
  2. Write the tests in a way you expect your users to use the API
  3. Some edge case might be better documented by Rspec or something similar and is not exposed to your users

Something I tend to do:

Something like that - not tested.

Scenario: No Instance method contract violation
  Given a file named "contract.rb" with:
  """ruby
  require "contracts"
  C = Contracts

  class Example
    include Contracts::Core

    Contract C::Num, C::Num => C::Num
    def add(a, b)
      a + b
    end
  end
  """
  And a file named "spec/instance_method_violation_spec.rb" with:
  """
  require 'contract.rb'

  RSpec.describe "instance method violation" do
    subject { Example.new }

    let(:a) { 1 }
    let(:b) { 2 }

    it { expect(subject.add(a, b)).to eq 3 }
  end
  """
  When I run `rspec`
  Then the specs should all pass

Scenario: Instance method contract violation
  Given a file named "contract.rb" with:
  """ruby
  require "contracts"
  C = Contracts

  class Example
    include Contracts::Core

    Contract C::Num, C::Num => C::Num
    def add(a, b)
      a + b
    end
  end
  """
  And a file named "spec/instance_method_violation_spec.rb" with:
  """
  require 'contract.rb'

  RSpec.describe "instance method violation" do
    subject { Example.new }

    let(:a) { 1 }
    let(:b) { 'a' }

    it { expect { subject.add(a, b) }.to raise_error ParamContractError }
  end
  """
  When I run `rspec`
  Then the specs should all pass

Using this approach you do not need to do something like puts XY but you can use the same "synatx" your users are using.

Hope this makes sense to you.

@sfcgeorge
Copy link
Contributor

Oh this is pretty cool, nice!

@alex-fedorov
Copy link
Collaborator

@dg-ratiodata For contract violation errors I wanted to demonstrate exactly how error looks like and what data it has inside. How would you do that with RSpec ?

@ghost
Copy link

ghost commented Sep 8, 2015

Oh, ok. But what about something like that:

let(:error_message) { <<-EOS
    : Contract violation for argument 2 of 2: (ParamContractError)
            Expected: Num,
            Actual: "foo"
            Value guarded in: Example::add
            With Contract: Num, Num => Num
            At: instance_method_violation.rb:8
EOS
}

it { expect { subject.add(a, b) }.to raise_error ParamContractError,  error_message }

@waterlink
Copy link
Collaborator Author

That sounds good. I will try it out. Thanks! :)

Best Regards,
Alexey Fedorov,
Sr Ruby, Clojure, Crystal, Golang Developer,
Microservices Backend Engineer,
+49 15757 486 476

2015-09-08 9:27 GMT+02:00 Dennis Günnewig notifications@github.com:

Oh, ok. But what about something like that:

let(:error_message) { <<-EOS : Contract violation for argument 2 of 2: (ParamContractError) Expected: Num, Actual: "foo" Value guarded in: Example::add With Contract: Num, Num => Num At: instance_method_violation.rb:8EOS
}

it { expect { subject.add(a, b) }.to raise_error ParamContractError, error_message }


Reply to this email directly or view it on GitHub
#195 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants