Git Product home page Git Product logo

betterspecs's Introduction

betterspecs.org

Source code for alpha.betterspecs.org

Requirements

RSpec Best Practices website is tested against MRI 2.7.0

Installation

git clone [email protected]:betterspecs/betterspecs.git
cd betterspecs
bundle install
bundle exec jekyll serve

Resources

alpha.betterspecs.org

Contributing

Fork the repo on github and send a pull requests with topic branches.

Feedback

Use the issue tracker for bugs.

Links

Authors

Andrea Reginato

Contributors

Special thanks to the following people for submitting patches.

Changelog

See CHANGELOG

License

Betterspecs is released under the MIT License.

betterspecs's People

Contributors

akira-kuriyama avatar akz92 avatar andreareginato avatar benoittgt avatar blueplanet avatar cga1123 avatar codebycliff avatar dakariakin avatar dannielb avatar dependabot[bot] avatar dwy6626 avatar edwardpark avatar kanata2 avatar olleolleolle avatar onebree avatar rhannequin avatar storrence88 avatar vtorves avatar yefrem avatar zachhaitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

betterspecs's Issues

Code error in bad example for let/let! section

describe '#type_id' do
  before { @resource = FactoryGirl.create :device }
  before { @type     = Type.find resource.type_id }
  ...

I think the @type before-block means to reference @resource, not resource; I think this is a copy-paste error from the "good" example below.

Mock or not to mock guideline's example is actually a stub

Update that guideline to talk about a mock, using something with

expect(something).to receive

Maybe add another guideline describing if you should use a mock or a stub, explaining when to use:

allow(something).to receive 

or

expect(something).to receive

Expect vs Should syntax

In the following text Myron says to use this on new projects.

You guys think this is a good section to better specs? I personaly have use this on new projects with configuration to use only new syntax.

Creating a quizz based on the questions

Hello!

it could be very engaging/fun for people to answer a quizz based on the questions that you would have in the best practices "database", and compute a score based on their correct results etc, so that people can evaluate themselves and improve over time.

Obviously for this to work, you would have to stick to best practices that are rather universally agreed upon as being the best option, rather than things that are more a matter of taste (and the line is sometimes tricky to trace here).

Merge latest PR changes into gh-pages

After the move to v2.0, I merged some PRs into master, not realizing that the bulk of the content is not on the gh-pages branch.

  • #165 - "Here a" typo
  • Manually merge other PRs into gh-pages branch (not currently selected)
  • Change default branch from master to gh-pages (@andreareginato)
    • Add blurb in "Contributing" about new default branch (#174)
    • If we make gh-pages the default, do we even need a "master" branch?
  • Merge changes from master into (and before) gh-pages

Update site content for Rails4/RSpec3

I think it is important to still keep current best practices, but label older ones as for RSpec 2. Many teams and online classes still use RSpec2, and it is important to maintain compatibility.

  • Clarify whether a best practice is for only RSpec2 or RSpec3
  • Update all reference links (#139, #141)
  • Replace Spork recommendation with Spring (Rails 4)
  • Update gems in project, and recommended gems on site
  • Research other best practices site, and include (and attribute) content if needed
  • Translate all changes into other languages
  • Write guidelines in second-person (#142)
  • Banner explaining the use of older Rails/RSpec versions and site maintenance (#141 (comment))

Add existing matchers and helpers to RSpec

You want your specs to be short and sweet. Sometimes some libs provide custom matchers and helpers that can make your "testing life" easy.

let(:user) { FactoryGirl.build :user }
let(:other_user) { FactoryGirl.create :other_user }

After extending your RSpec.configure block with some methods.

RSpec.configure do
  config.include FactoryGirl::Syntax::Methods
  ...
end

You can just write.

let(:user) { build :user }
let(:other_user) { create :other_user }

Same goes for Rack::Test::Methods mixin.

Question / Possible addition

I am surfing around and bumped into a stack overflow where two people voiced the opinion that expectations should not be put into a before hook. The expectations should be put into the example. A third person argued the other way because it was dryer.

I bopped over to here to see what your thoughts are and I don't see the topic discussed. Perhaps this is something that could be added: If the same expectation is going to be applied in (all / most) of the examples of a given context, should that expectation be put into a before block (or what I did was put it inside the let block).

Update roadmap, seeking collaborators!

In the past few weeks, betterspecs has gained some new collaborators to the repository. While everyone on the team is enthusiastic, we have huge plans and need some additional help!

For complete transparency, here is an unordered list of things we would like to accomplish:

  • Obtain more collaborators, especially those who can help monitor translations
  • Convert the website (now hosted on Heroku) to a Github Page powered by Jekyll (#153)
  • Develop a versioning style, and apply it to all translations. EN would be the most current, with all translations attempting to follow.
    • Possibly moving each translation to its own branch or directory within the repository.
    • We want to use version numbers on the individual translations, we we believe it will help keep them in sync with EN (#20, #78)
  • Create a blog and newsletter for website and repository updates
  • Also see issue #144

Feel free to leave comments on any ideas you may have.

If you are interested in becoming a collaborator, please email @andreareginato (see profile), as he is the owner of this repository.

License is unusable

I know licensing can be a touchy issue, so I hope I don't offend anyone. Currently the LICENSE.md file contains a simple copyright notice. If no other license is granted, then I can't legally make a copy of this project or modify it for my own use. Ideally I would like to fork this project and use it as part of the standards in my group. I would like to modify it to apply to our group's standards. One of the CC licenses would be nice. It appears that this is intended to be allowed (as the project has already been forked 42 times), but if I'm wrong feel free to ignore this.

Q: Best practice for mocks expectations?

Hi,

I was wondering what is the best practice for mocks expectations:

Instead of:

it 'will receive create' do
    VendorSchedulable.should_receive(:create).with(:some, :other)
    CreateVendorSchedule.create(:some, :other)
end

I am wirting

before do
  VendorSchedulable.stub(:create)
  CreateVendorSchedule.create(42, 'deal-43')
end

it { expect(VendorSchedulable).to have_received(:create) }

But I don't really like it { expect

Guidance phrased as personal opinion

BetterSpecs seems to be intended as a community effort, but many the explanations use the word 'I' since the were originally written by @andreareginato.

I believe this discourages others from contributing updates advice. I would suggest taking an approach similar to the Ruby Style Guide, where the guidance is intended to capture the community's collective viewpoint, so is written from a non-personal point of view.

rubocop-rspec

rubocop-rspec (an extension to rubocop) is a tool to check the code style of RSpec files. Maybe you can promote it somewhere on the betterspecs.org page?

Some of the rules of betterspecs.org are already in there, like: "Use let and let!", "Do not use should" or checks for the file name, or to enforce the use of described_class.

If you have new ideas what could be checked with this tool let me know.

Random specs

In order that capture related spec, I suggest put a topic about random specs.
I saw a lot of projects not using (and disabling this option from rspec)

Consider alternative to best practice term

Best practice is a term used in betterspecs. Practices are dependent on context. There can be multiple conflicting but good practices with no clear winner. Best practice misses this nuance unfortunately. Best practice discourages independent and critical thought of the practices presented which is an unintended consequence.

Looking forward

I finished translating betterspecs to russian language, and now I am sure, that it will be very hard to support the whole app in future. Here is the list of things that I think will improve the awesomness of betterspecs.org:

  • Layout must be DRY and reusable.
  • Menu items must be auto-generated from headers instead of being inserted manualy.
  • Same with social buttons.
  • Same with additional info links.
  • Translations should be more maintanable. It will be great if the translation maintainer could receive a letter when some practice was added or changed in original version of the betterspecs.
  • Practices should be voted and discussed on the site, not on the github.

In other words, we should start saving data to the DB and write some ruby code to do it more usable. What do you think?

Thanks.

link to method documentation

E.g. if someone's never used context before, they will want to see other examples of how it's used. I imagine in most cases this will link to the RDoc and/or Relish pages.

Move from Heroku to Github Pages

Previous participants: @andreareginato , @akz92

As discussed in issue #146, we want to move away from Heroku and instead host the site on Github. Some advantages include:

  • Quicker deployment
  • Free site hosting (by Github)
  • Built-in Markdown support when using Jekyll
  • Little to no required downtime
  • No need to give collaborators access to an additional service (Heroku)
  • Others can easily test their pull requests by calling: jekyll serve -h 0.0.0.0 -p 4000

To see a current live demo of the beta site: https://github.com/akz92/akz92.github.io

Checklist of features for demo site:

  • [x] Syntax highlighting (Ruby)
  • [x] Mobile-friendly website (akz92/akz92.github.io#1)
  • [ ] Disqus compatibility (hopefully deprecating Github issues as "thoughts".
    • Open to other discussion platforms that possibly recognize Markdown.
  • [ ] Tedious, but change all tabs to spaces in code (huge pet-peeve of mine!)

Please place all discussion about the site construction here!

How do you describe readers and writers?

Hello, @andreareginato. I would like to know your opinion.

Let's say we have this code:

class Dog
  attr_reader :gender
  attr_accessor :name

  def initialize(gender: gender)
    @gender = gender
  end
end

And the spec might look like this:

describe Dog do
  describe '#gender' do
    it 'provides reading of a gender' do
      dog = Dog.new(gender: 'male')
      expect(dog.gender).to eq('male')
    end
  end

  describe '#name' do
    it 'provides writing and reading of a name' do
      dog = Dog.new(gender: 'female')

      dog.name = 'Stella'

      expect(dog.name).to eq('Stella')
    end
  end
end

What do you think about descriptions? How would you test such code?

Add links swich different languages

On the top menu (probably on the right) we need to insert the capability to choose different languages for better specs. Rght now we have korean and russian translations.

Add 'rspec best practices with ruby' in the html title tag

Hello,

adding '{ rspec best practices with ruby }' (with or without braces) to the html title tag let people who manage his visited sites searchng the browser address bar (like me) to write 'rspec best practices' in the bar and find your site if they visited it before.

Moreover, it will increase the rank of the site in the google search 'rspec best practices'.


Per dirtela in una lingua comune: io non uso i segnalibri, trovo che la ricerca nella cronologia della barra degli indirizzi del browser sia più veloce e comoda. Per cui mi piacerebbe che scrivendo 'rspec best practices' nella barra degli indirizzi mi apparisse il tuo sito, che invece non appare dato che la ricerca nella barra degli indirizzi cerca nell'URL e nell'html tag title - almeno, quella di Firefox fa così, le altre non so.

Tra l'altro, anche cercando su Google 'rspec best practices' non riesco a trovae il tuo sito.

In sostanza me l'ero perso; per fortuna ero arrivato al tuo sito tramite Hacker News, per cui scrivendo nell'URL 'rspec best practices' mi ha tirato fuori la segnalazione di Hacker News relativa al sito.

Ah, complimenti per l'idea, proprio bella :-)

Q: Where should I place the mocks in my test?

describe '#method1' do
  before { expect(SomeClass).to receive(:method2) }
  subject { described_class.new.method1 }

  it 'calls SomeClass.method2' do
    subject
  end
end

VS

describe '#method1' do
  subject { described_class.new.method1 }

  it 'calls SomeClass.method2' do
    expect(SomeClass).to receive(:method2)
    subject
  end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.